String Contains

Benchmark created by Ravishanker Kusuma on


Test runner

Ready to run.

Testing in
TestOps/sec
greater than - indexOf()
var str = "This is string comparison test.Which one is best ?";

function contains(r, s) {
  return r.indexOf(s) > -1;
}
contains(str, 'best');
ready
not equivalent - indexOf()
var str = "This is string comparison test.Which one is best ?";

function contains(r, s) {
  return r.indexOf(s) !== -1;
}
contains(str, 'best');
ready
with bitwise not- indexOf()
var str = "This is string comparison test.Which one is best ?";

function contains(r, s) {
  return !!~r.indexOf(s);
}
contains(str, 'best');
ready
greater than - search()
var str = "This is string comparison test.Which one is best ?";

function contains(r, s) {
  return r.search(s) > -1;
}
contains(str, 'best');
ready
not equal - serach()
var str = "This is string comparison test.Which one is best ?";

function contains(r, s) {
  return r.search(s) !== -1;
}
contains(str, 'best');
ready
with bitwise not - search()
var str = "This is string comparison test.Which one is best ?";

function contains(r, s) {
  return !!~r.search(s);
}
contains(str, 'best');
ready

Revisions

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

  • Revision 1: published by Ravishanker Kusuma on