Created
November 30, 2017 07:08
-
-
Save thevtm/357befbd285eda3bab635f20f43a2563 to your computer and use it in GitHub Desktop.
zeit/ms parse regex benchmark
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
Benchmarking 6 regexes for 18 test cases | |
Benchmarking test case: "17697971165612536521198392175651265616253619638124 minutes" | |
original x 4,228,677 ops/sec ±1.47% (86 runs sampled) | |
prototype0 x 4,329,400 ops/sec ±2.68% (81 runs sampled) | |
prototype1 x 4,015,480 ops/sec ±2.31% (83 runs sampled) | |
prototype2 x 4,621,512 ops/sec ±1.20% (88 runs sampled) | |
prototype3 x 4,516,519 ops/sec ±0.75% (90 runs sampled) | |
***totype4 x 4,729,367 ops/sec ±1.01% (88 runs sampled) | |
Fastest is ***totype4 | |
Benchmarking test case: "176979711656125365211983921756512656162536196381246652653816351862351635128635123651283615 hours" | |
original x 3,823,566 ops/sec ±0.89% (91 runs sampled) | |
prototype0 x 3,901,167 ops/sec ±1.25% (91 runs sampled) | |
prototype1 x 3,651,586 ops/sec ±2.19% (89 runs sampled) | |
prototype2 x 3,967,858 ops/sec ±1.17% (86 runs sampled) | |
prototype3 x 3,889,786 ops/sec ±1.33% (90 runs sampled) | |
***totype4 x 3,957,852 ops/sec ±1.89% (88 runs sampled) | |
Fastest is prototype2 | |
Benchmarking test case: "17697971165612536521198392175651265616253619638124u" | |
original x 23,290 ops/sec ±0.89% (91 runs sampled) | |
prototype0 x 5,026,260 ops/sec ±1.27% (90 runs sampled) | |
prototype1 x 4,981,992 ops/sec ±0.93% (88 runs sampled) | |
prototype2 x 5,212,035 ops/sec ±1.05% (90 runs sampled) | |
prototype3 x 5,236,085 ops/sec ±0.73% (90 runs sampled) | |
***totype4 x 5,210,498 ops/sec ±1.22% (89 runs sampled) | |
Fastest is prototype3,prototype2,***totype4 | |
Benchmarking test case: "11276979711656125365211983921756512656162536196381246652653816351862351635128635123651283615t" | |
original x 7,140 ops/sec ±0.58% (92 runs sampled) | |
prototype0 x 4,090,554 ops/sec ±1.13% (90 runs sampled) | |
prototype1 x 4,103,369 ops/sec ±0.69% (89 runs sampled) | |
prototype2 x 4,176,584 ops/sec ±1.84% (87 runs sampled) | |
prototype3 x 4,065,549 ops/sec ±2.80% (85 runs sampled) | |
***totype4 x 4,235,829 ops/sec ±1.23% (90 runs sampled) | |
Fastest is ***totype4,prototype2,prototype3 | |
Benchmarking test case: "1 kaspokdasokdpsokdoskdokadpokkspokdsoaskdpaokdknad" | |
original x 9,369,828 ops/sec ±0.64% (90 runs sampled) | |
prototype0 x 5,043,976 ops/sec ±1.16% (86 runs sampled) | |
prototype1 x 3,527,315 ops/sec ±0.69% (90 runs sampled) | |
prototype2 x 4,934,867 ops/sec ±1.13% (91 runs sampled) | |
prototype3 x 6,052,815 ops/sec ±0.61% (91 runs sampled) | |
***totype4 x 4,947,723 ops/sec ±1.31% (91 runs sampled) | |
Fastest is original | |
Benchmarking test case: "5 kaspokdasokdpsokdoskdokadpokkspokdsoaskdpaokdknadkaspokdasokdpsokdoskdokadpokkspokdsoaskdpasa" | |
original x 9,372,758 ops/sec ±0.92% (89 runs sampled) | |
prototype0 x 3,842,412 ops/sec ±1.99% (87 runs sampled) | |
prototype1 x 3,360,959 ops/sec ±2.30% (83 runs sampled) | |
prototype2 x 3,896,439 ops/sec ±1.58% (89 runs sampled) | |
prototype3 x 6,037,591 ops/sec ±0.61% (88 runs sampled) | |
***totype4 x 4,020,403 ops/sec ±0.54% (89 runs sampled) | |
Fastest is original | |
Benchmarking test case: "2 u3h1u2h3ou12h3o1u23hou12h31u23huhuhouho2uh3o12uh4ouh41o2uh4o12uh" | |
original x 8,947,379 ops/sec ±2.66% (87 runs sampled) | |
prototype0 x 4,563,769 ops/sec ±1.40% (90 runs sampled) | |
prototype1 x 3,516,833 ops/sec ±0.58% (87 runs sampled) | |
prototype2 x 4,505,107 ops/sec ±1.52% (86 runs sampled) | |
prototype3 x 6,085,762 ops/sec ±0.53% (91 runs sampled) | |
***totype4 x 4,586,430 ops/sec ±1.88% (83 runs sampled) | |
Fastest is original | |
Benchmarking test case: "3 h3o1u23hou12h31u23huhuhouho2uh3o12uh4ouh41o2uh4o12uhh3o1u23hou12h31u23huhuhouho2uh3o12uh4ouh4" | |
original x 7,895,179 ops/sec ±0.92% (90 runs sampled) | |
prototype0 x 4,013,067 ops/sec ±1.68% (88 runs sampled) | |
prototype1 x 3,511,122 ops/sec ±0.55% (89 runs sampled) | |
prototype2 x 3,997,945 ops/sec ±1.17% (89 runs sampled) | |
prototype3 x 6,009,932 ops/sec ±0.73% (89 runs sampled) | |
***totype4 x 4,079,874 ops/sec ±1.10% (90 runs sampled) | |
Fastest is original | |
Benchmarking test case: "512313312312312312312415656546646456456456456464 dkaspokdasokdpsokdoskdokadpokkspokdsoaskdpasasda" | |
original x 23,129 ops/sec ±0.95% (90 runs sampled) | |
prototype0 x 3,829,068 ops/sec ±1.40% (84 runs sampled) | |
prototype1 x 5,139 ops/sec ±0.77% (89 runs sampled) | |
prototype2 x 3,851,941 ops/sec ±1.13% (88 runs sampled) | |
prototype3 x 11,096 ops/sec ±0.49% (92 runs sampled) | |
***totype4 x 3,834,794 ops/sec ±1.25% (88 runs sampled) | |
Fastest is prototype2,***totype4,prototype0 | |
Benchmarking test case: "312314112871208372837102837203816376219371623716uh4o12uhh3o1u23hou12h31u23huhuhouho2uh3o12uh4ouh4" | |
original x 24,449 ops/sec ±1.82% (88 runs sampled) | |
prototype0 x 3,782,997 ops/sec ±1.87% (87 runs sampled) | |
prototype1 x 4,304 ops/sec ±0.81% (90 runs sampled) | |
prototype2 x 3,893,731 ops/sec ±1.09% (90 runs sampled) | |
prototype3 x 9,721 ops/sec ±0.56% (92 runs sampled) | |
***totype4 x 3,828,618 ops/sec ±1.17% (89 runs sampled) | |
Fastest is prototype2,prototype0 | |
Benchmarking test case: "8712873871038712837128378.1361927639169321766 mins" | |
original x 4,909,690 ops/sec ±0.79% (90 runs sampled) | |
prototype0 x 4,942,580 ops/sec ±2.66% (87 runs sampled) | |
prototype1 x 4,976,958 ops/sec ±1.12% (87 runs sampled) | |
prototype2 x 5,406,148 ops/sec ±0.66% (92 runs sampled) | |
prototype3 x 5,059,641 ops/sec ±1.73% (87 runs sampled) | |
***totype4 x 5,270,681 ops/sec ±1.40% (85 runs sampled) | |
Fastest is prototype2 | |
Benchmarking test case: "87128738710387128371283781778731287371873981277892.136192763916932176693217631762917623679 mins" | |
original x 3,738,093 ops/sec ±1.16% (91 runs sampled) | |
prototype0 x 3,918,646 ops/sec ±1.26% (88 runs sampled) | |
prototype1 x 3,696,085 ops/sec ±1.80% (84 runs sampled) | |
prototype2 x 4,040,491 ops/sec ±0.42% (90 runs sampled) | |
prototype3 x 3,918,949 ops/sec ±1.25% (89 runs sampled) | |
***totype4 x 3,774,772 ops/sec ±3.49% (84 runs sampled) | |
Fastest is prototype2 | |
Benchmarking test case: "8712873871038712837128378.1361927639169321766 ares" | |
original x 81,393 ops/sec ±1.10% (88 runs sampled) | |
prototype0 x 5,096,801 ops/sec ±1.85% (90 runs sampled) | |
prototype1 x 5,013,797 ops/sec ±0.84% (87 runs sampled) | |
prototype2 x 5,417,364 ops/sec ±0.79% (89 runs sampled) | |
prototype3 x 5,083,825 ops/sec ±2.18% (88 runs sampled) | |
***totype4 x 5,179,687 ops/sec ±2.86% (88 runs sampled) | |
Fastest is prototype2 | |
Benchmarking test case: "87128738710387128371283781778731287371873981277892.136192763916932176693217631762917623679 min41s" | |
original x 21,939 ops/sec ±0.91% (92 runs sampled) | |
prototype0 x 3,901,729 ops/sec ±1.52% (87 runs sampled) | |
prototype1 x 3,719,533 ops/sec ±0.57% (88 runs sampled) | |
prototype2 x 3,793,287 ops/sec ±1.80% (89 runs sampled) | |
prototype3 x 3,635,007 ops/sec ±1.75% (86 runs sampled) | |
***totype4 x 3,817,470 ops/sec ±1.97% (85 runs sampled) | |
Fastest is prototype0,***totype4 | |
Benchmarking test case: "1412 seconds" | |
original x 5,191,672 ops/sec ±1.53% (89 runs sampled) | |
prototype0 x 4,643,288 ops/sec ±4.21% (81 runs sampled) | |
prototype1 x 4,805,928 ops/sec ±0.84% (90 runs sampled) | |
prototype2 x 5,073,495 ops/sec ±2.34% (89 runs sampled) | |
prototype3 x 5,010,611 ops/sec ±0.81% (89 runs sampled) | |
***totype4 x 5,384,853 ops/sec ±1.31% (91 runs sampled) | |
Fastest is ***totype4 | |
Benchmarking test case: "1412 mins" | |
original x 3,741,709 ops/sec ±1.07% (86 runs sampled) | |
prototype0 x 3,935,251 ops/sec ±0.67% (90 runs sampled) | |
prototype1 x 3,809,600 ops/sec ±0.87% (89 runs sampled) | |
prototype2 x 3,954,918 ops/sec ±1.37% (91 runs sampled) | |
prototype3 x 3,904,584 ops/sec ±0.55% (91 runs sampled) | |
***totype4 x 4,014,167 ops/sec ±1.20% (89 runs sampled) | |
Fastest is ***totype4 | |
Benchmarking test case: "1412 umoap" | |
original x 364,609 ops/sec ±0.49% (90 runs sampled) | |
prototype0 x 5,004,094 ops/sec ±3.07% (87 runs sampled) | |
prototype1 x 5,004,884 ops/sec ±1.37% (88 runs sampled) | |
prototype2 x 5,404,182 ops/sec ±1.58% (85 runs sampled) | |
prototype3 x 5,238,084 ops/sec ±1.07% (90 runs sampled) | |
***totype4 x 5,541,999 ops/sec ±1.21% (91 runs sampled) | |
Fastest is ***totype4 | |
Benchmarking test case: "1412 eoi" | |
original x 128,665 ops/sec ±0.74% (92 runs sampled) | |
prototype0 x 3,795,001 ops/sec ±1.64% (89 runs sampled) | |
prototype1 x 3,833,293 ops/sec ±0.86% (90 runs sampled) | |
prototype2 x 4,016,564 ops/sec ±1.13% (92 runs sampled) | |
prototype3 x 3,987,291 ops/sec ±0.84% (91 runs sampled) | |
***totype4 x 3,937,528 ops/sec ±1.65% (87 runs sampled) | |
Fastest is prototype2,***totype4 | |
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
'use strict' | |
/* | |
Modules | |
*/ | |
const Benchmark = require('benchmark') | |
const regexes = [ | |
{ name: 'original', regex: /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i }, | |
{ name: 'prototype0', regex: /^((?:\d+)?\.?\d+) *(\w*)?$/i }, | |
{ name: 'prototype1', regex: /^((?:\d+)?\.?\d+) *(\w{0,12})?$/i }, | |
{ name: 'prototype2', regex: /^((?:\d+)?\.?\d+) *(\w*)$/i }, | |
{ name: 'prototype3', regex: /^((?:\d+)?\.?\d+) *(\w{0,12})$/i }, | |
{ name: '***totype4', regex: /^(-?(?:\d+)?\.?\d+) *(\w*)$/i }, | |
]; | |
const test_cases = [ | |
// '1s', | |
// '1769797116 milliseconds', | |
'17697971165612536521198392175651265616253619638124 minutes', | |
'176979711656125365211983921756512656162536196381246652653816351862351635128635123651283615 hours', | |
// '6z', | |
// '1769797116 x', | |
'17697971165612536521198392175651265616253619638124u', | |
'11276979711656125365211983921756512656162536196381246652653816351862351635128635123651283615t', | |
'1 kaspokdasokdpsokdoskdokadpokkspokdsoaskdpaokdknad', | |
'5 kaspokdasokdpsokdoskdokadpokkspokdsoaskdpaokdknadkaspokdasokdpsokdoskdokadpokkspokdsoaskdpasa', | |
'2 u3h1u2h3ou12h3o1u23hou12h31u23huhuhouho2uh3o12uh4ouh41o2uh4o12uh', | |
'3 h3o1u23hou12h31u23huhuhouho2uh3o12uh4ouh41o2uh4o12uhh3o1u23hou12h31u23huhuhouho2uh3o12uh4ouh4', | |
'512313312312312312312415656546646456456456456464 dkaspokdasokdpsokdoskdokadpokkspokdsoaskdpasasda', | |
'312314112871208372837102837203816376219371623716uh4o12uhh3o1u23hou12h31u23huhuhouho2uh3o12uh4ouh4', | |
// '1.5h', | |
// '18123.68791 ms', | |
'8712873871038712837128378.1361927639169321766 mins', | |
'87128738710387128371283781778731287371873981277892.136192763916932176693217631762917623679 mins', | |
// '1.5zz', | |
// '18123.68791 ads', | |
'8712873871038712837128378.1361927639169321766 ares', | |
'87128738710387128371283781778731287371873981277892.136192763916932176693217631762917623679 min41s', | |
// '1 s', | |
'1412 seconds', | |
'1412 mins', | |
// '1 ter', | |
'1412 umoap', | |
'1412 eoi', | |
] | |
console.log(`Benchmarking ${regexes.length} regexes for ${test_cases.length} test cases\n`); | |
for (const test_case of test_cases) { | |
console.log(`Benchmarking test case: "${test_case}"\n`); | |
const suite = new Benchmark.Suite; | |
suite.on('cycle', function(event) { | |
console.log(String(event.target)); | |
}) | |
.on('complete', function() { | |
console.log(); | |
console.log('Fastest is ' + this.filter('fastest').map('name')); | |
}); | |
for (const regex of regexes) { | |
suite.add(regex.name, function() { | |
var match = regex.regex.exec(test_case); | |
}) | |
} | |
suite.run({ async: false }); | |
console.log(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment