Last active
July 9, 2021 18:36
-
-
Save alsotang/6219f16d86a30ac5b795f8fa035931ac to your computer and use it in GitHub Desktop.
determin_ascii.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
js logic x 8,931,284 ops/sec ±0.48% (90 runs sampled) | |
re x 9,434,634 ops/sec ±0.66% (92 runs sampled) | |
Fastest is re | |
*/ | |
const Benchmark = require('benchmark') | |
var suite = new Benchmark.Suite; | |
const str = 'aldfkjlakdsjflajkdsflakjdfjzakljerowiuetoywoihgkhgkzjcvlzcnvkjsdfbalhdfl' | |
const start = 65; | |
const end = 122 | |
// add tests | |
suite.add('js logic', function() { | |
for (let i = 0; i < str.length; i++) { | |
const charCode = str.charCodeAt(i) | |
charCode >= 65 && charCode <= 122; | |
} | |
}) | |
.add('re', function() { | |
/^[a-zA-Z]+$/.test(str) | |
}) | |
// add listeners | |
.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function() { | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}) | |
// run async | |
.run({ 'async': true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment