File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ "use strict" ;
2+ const inv = require ( "install-npm-version" ) ;
3+ const benchmarkVersion = "1.0.1" ;
4+ const benchmarkLib = `postcode@${ benchmarkVersion } ` ;
5+
6+ const message = `
7+ Benchmarking master against ${ benchmarkLib }
8+
9+ ` ;
10+
11+ inv
12+ . Install ( benchmarkLib , { Verbosity : "debug" } )
13+ . then ( ( ) => runBenchmarks ( ) )
14+ . catch ( error => {
15+ console . log ( error ) ;
16+ process . exit ( 1 ) ;
17+ } ) ;
18+
19+ const runBenchmarks = ( ) => {
20+ const { Suite } = require ( "benchmark" ) ;
21+ const suite = new Suite ( ) ;
22+
23+ const Postcode = require ( "./dist/index" ) ;
24+ const PreviousPostcode = require ( benchmarkLib ) ;
25+
26+ const extractInputs = ( { tests } ) => tests . map ( ( { base } ) => base ) ;
27+
28+ const validation = extractInputs ( require ( "./test/data/validation.json" ) ) ;
29+ suite
30+ . add ( `(version: ${ benchmarkVersion } ) Postcode#valid` , ( ) => {
31+ validation . forEach ( postcode => {
32+ const result = new PreviousPostcode ( postcode ) . valid ( ) ;
33+ } ) ;
34+ } )
35+ . add ( "(version: master) Postcode.isValid" , ( ) => {
36+ validation . forEach ( postcode => {
37+ const result = Postcode . isValid ( postcode ) ;
38+ } ) ;
39+ } )
40+ . on ( "cycle" , event => {
41+ console . log ( String ( event . target ) ) ;
42+ } )
43+ . run ( { } ) ;
44+ } ;
You can’t perform that action at this time.
0 commit comments