perf.js
1 var jmespath = require('./jmespath') 2 var Benchmark = require('benchmark'); 3 var suite = new Benchmark.Suite; 4 5 // add tests 6 suite.add('Parser#single_expr', function() { 7 jmespath.compile("foo"); 8 }) 9 .add('Parser#single_subexpr', function() { 10 jmespath.compile("foo.bar"); 11 }) 12 .add('Parser#deeply_nested_50', function() { 13 jmespath.compile("j49.j48.j47.j46.j45.j44.j43.j42.j41.j40.j39.j38.j37.j36.j35.j34.j33.j32.j31.j30.j29.j28.j27.j26.j25.j24.j23.j22.j21.j20.j19.j18.j17.j16.j15.j14.j13.j12.j11.j10.j9.j8.j7.j6.j5.j4.j3.j2.j1.j0"); 14 15 }) 16 .add('Parser#deeply_nested_50_index', function() { 17 jmespath.compile("[49][48][47][46][45][44][43][42][41][40][39][38][37][36][35][34][33][32][31][30][29][28][27][26][25][24][23][22][21][20][19][18][17][16][15][14][13][12][11][10][9][8][7][6][5][4][3][2][1][0]"); 18 }) 19 .add('Parser#basic_list_projection', function() { 20 jmespath.compile("foo[*].bar"); 21 }) 22 .on('cycle', function(event) { 23 var bench = event.target; 24 var mean = bench.stats.mean * 1000; 25 var variance = bench.stats.variance * 1000000; 26 var result = 'Mean time: ' + mean.toFixed(6) + 'msec '; 27 result += event.target.toString(); 28 console.log(result); 29 }) 30 .on('complete', function() { 31 }) 32 // run async 33 .run({ 'async': false });