Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Count string period occurrence
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser:
Chrome 136
Operating system:
Windows
Device Platform:
Desktop
Date tested:
11 months ago
Test name
Executions per second
Use regex
8797397.0 Ops/sec
Use split with regex
7699239.5 Ops/sec
Use forloopset
2251794.2 Ops/sec
forloop2
11083674.0 Ops/sec
Script Preparation code:
function regex(s) { var r = s.match(/[..。。]/g); if (r) return r.length; return 0; } function split(s) { return s.split(/[..。。]/).length - 1; } function forloopset(s, oc) { let c = 0; for (let i =0; i < s.length; i++){ if (oc.has(s[i])) c++} return c; } function forloop(s) { let c = 0; for (let i =0; i < s.length; i++){ if (s[i] ==="."|| s[i] === "."|| s[i] === "。"|| s[i] === "。") c++} return c; }
Tests:
Use regex
regex("This is a pen. This is a pen。 Another one.");
Use split with regex
split("This is a pen. This is a pen。 Another one.");
Use forloopset
forloopset("This is a pen. This is a pen。 Another one.", new Set([".",".","。","。"]));
forloop2
forloop("This is a pen. This is a pen。 Another one.");