substr vs regex

Benchmark created by Aboubakr Gasmi on


Description

Sub string existance check

Setup

var compiledRe = /\.css$/;
    var compiledGeneratedRe = new RegExp('.css$');
    var isCss;

Test runner

Ready to run.

Testing in
TestOps/sec
Substr
if ('/path/to/file.css'.substr(-4) === '.css') {
  isCss = true;
}
ready
compiled Regex
if (compiledRe.test('/path/to/file.css')) {
  isCss = true;
}
ready
Compiled generated regex
if (compiledGeneratedRe.test('/path/to/file.css')) {
  isCss = true;
}
ready
Inline regex
if (/\.css$/.test('/path/to/file.css')) {
  isCss = true;
}
ready

Revisions

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

  • Revision 1: published by Aboubakr Gasmi on