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:
one year ago
forloop2
11.1M/s
Use regex
8.8M/s
Use split with regex
7.7M/s
Use forloopset
2.3M/s
View exact numbers
Test name
Executions per second
✓
forloop2
11,083,674 Ops/sec
Use regex
8,797,397 Ops/sec
Use split with regex
7,699,240 Ops/sec
Use forloopset
2,251,794 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.");