Created
August 23, 2016 13:16
-
-
Save zloyrusskiy/b725dd2ca325d941ad6d2c7330979ad9 to your computer and use it in GitHub Desktop.
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
var Benchmark = require('benchmark'); | |
var suite = new Benchmark.Suite; | |
// add tests | |
suite.add('lowercase', function() { | |
let input = 'ai'; | |
let dictionary = ['airplane','airport','apple','ball']; | |
var clean_str = input.replace(/[^a-z]+/gi,'').toLowerCase(); | |
let res = dictionary | |
.filter(x => x.toLowerCase().startsWith(clean_str)) | |
.slice(0,5); | |
}) | |
.add('regex', function() { | |
let input = 'ai'; | |
let dictionary = ['airplane','airport','apple','ball']; | |
var r = new RegExp('^' + input.replace(/[^a-z]/gi,''), 'i'); | |
let res = dictionary.filter(function(w){ return r.test(w); }).slice(0, 5); | |
}) | |
.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function() { | |
console.log(this); | |
}) | |
.run({ 'async': true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment