Generating slugs

JavaScript performance comparison

Test case created by Mathias Bynens and last updated

Preparation code

<script>
  // custom colors
  ui.browserscope.colors = ['pink', '#43C6DB'];

  var arr = [
   'This is just a test', // → "this-is-just-a-test"
   'Some “weird” characters: ©™® Awesome', // → "some-weird-characters-awesome"
   'Lorem ipsum 123 dolor' // → "lorem-ipsum-123-dolor"
  ];


</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Using several .replace()s
var i = arr.length;
while (i--) {
 arr[i].toLowerCase().replace(/[^a-z0-9-]+/g, '-').replace(/[-]+/g, '-').replace(/^-|-$/g, '');
};
pending…
Using .match() and .join()
var i = arr.length;
while (i--) {
 arr[i].toLowerCase().match(/[a-z0-9]+/ig).join('-');
};
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments