Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Performance.now() impact
(version: 1)
Comparing performance of:
indexOf vs indexOf + p.now vs indexOf + Date.now
Created:
10 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div></div>
Script Preparation code:
window.regexStart = /^test/; window.regexEnd = /test$/; window.match = 'test'; window.matchLength = window.match.length; var data = window.data = []; const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var TOTAL_STRINGS = window.TOTAL_STRINGS = 100000; function getRandomInt(max) { return Math.floor(Math.random() * max); } function makeRandomString(len) { var text = ""; for( var i=0; i < len; i++ ) { text += possible.charAt(getRandomInt(possible.length)); } return text; } while (data.length < TOTAL_STRINGS) { data.push(makeRandomString(getRandomInt(20))); }
Tests:
indexOf
var x = 0; var TOTAL_STRINGS = window.TOTAL_STRINGS; var data = window.data; var match = window.match; while (x < TOTAL_STRINGS) { const str = data[x]; str.indexOf(match) === 0; x += 1; }
indexOf + p.now
var x = 0; var TOTAL_STRINGS = window.TOTAL_STRINGS; var data = window.data; var match = window.match; while (x < TOTAL_STRINGS) { const str = data[x]; performance.now() str.indexOf(match) === 0; x += 1; performance.now() }
indexOf + Date.now
var x = 0; var TOTAL_STRINGS = window.TOTAL_STRINGS; var data = window.data; var match = window.match; while (x < TOTAL_STRINGS) { const str = data[x]; Date.now() str.indexOf(match) === 0; x += 1; Date.now() }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
indexOf
indexOf + p.now
indexOf + Date.now
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
indexOf
17408.5 Ops/sec
indexOf + p.now
57.8 Ops/sec
indexOf + Date.now
177.1 Ops/sec
Related benchmarks:
.indexOf vs .startsWith
.indexOf vs .startsWith vs .substr
startswith vs direct comparison
Regex vs .startsWith vs .indexOf vs .substr on string length 2000
startsWith vs RegExp
Regex vs endsWith vs indexOf vs lastIndexOf
startswith vs indexof??
JavaScript sub-string finding performance
Regex vs .indexOf & .lastIndexOf vs .startsWith & .endsWith
Comments
Confirm delete:
Do you really want to delete benchmark?