Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
math operation vs condition
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15
Browser:
Safari 16
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
math
411994.6 Ops/sec
condition
416288.0 Ops/sec
Tests:
math
const CaesarCipher = function (shift) { const code = (str, shift) => str.toUpperCase().replace(/[A-Z]/g, val => String.fromCharCode(65 + (val.charCodeAt() + shift - 65) % 26)); this.encode = str => code(str, shift); this.decode = str => code(str, 26 - shift); }; const c = new CaesarCipher(5); c.encode('Codewars') c.decode('HTIJBFWX')
condition
var CaesarCipher = function (shift) { this.shiftChar = (str, offset) => str.replace(/[a-z]/gi, (c) => { let charCode = c.toUpperCase().charCodeAt(0) + offset; if (charCode < 65) charCode += 26; else if (charCode > 90) charCode -= 26; return String.fromCharCode(charCode); }); this.encode = (str) => this.shiftChar(str, shift); this.decode = (str) => this.shiftChar(str, -shift); }; const c = new CaesarCipher(5); c.encode('Codewars') c.decode('HTIJBFWX')