1'use strict'; 2const common = require('../common.js'); 3 4const bench = common.createBenchmark(main, { 5 size: [16, 512, 4096, 16386], 6 args: [1, 2, 5], 7 n: [1e6] 8}); 9 10function main({ n, size, args }) { 11 const b0 = Buffer.alloc(size, 'a'); 12 const b1 = Buffer.alloc(size, 'a'); 13 const b0Len = b0.length; 14 const b1Len = b1.length; 15 16 b1[size - 1] = 'b'.charCodeAt(0); 17 18 switch (args) { 19 case 2: 20 b0.compare(b1, 0); 21 bench.start(); 22 for (let i = 0; i < n; i++) { 23 b0.compare(b1, 0); 24 } 25 bench.end(n); 26 break; 27 case 3: 28 b0.compare(b1, 0, b1Len); 29 bench.start(); 30 for (let i = 0; i < n; i++) { 31 b0.compare(b1, 0, b1Len); 32 } 33 bench.end(n); 34 break; 35 case 4: 36 b0.compare(b1, 0, b1Len, 0); 37 bench.start(); 38 for (let i = 0; i < n; i++) { 39 b0.compare(b1, 0, b1Len, 0); 40 } 41 bench.end(n); 42 break; 43 case 5: 44 b0.compare(b1, 0, b1Len, 0, b0Len); 45 bench.start(); 46 for (let i = 0; i < n; i++) { 47 b0.compare(b1, 0, b1Len, 0, b0Len); 48 } 49 bench.end(n); 50 break; 51 default: 52 b0.compare(b1); 53 bench.start(); 54 for (let i = 0; i < n; i++) { 55 b0.compare(b1); 56 } 57 bench.end(n); 58 } 59} 60