11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common.js'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 51cb0ef41Sopenharmony_ci method: ['offset', 'slice'], 61cb0ef41Sopenharmony_ci size: [16, 512, 4096, 16386], 71cb0ef41Sopenharmony_ci n: [1e6], 81cb0ef41Sopenharmony_ci}); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cifunction compareUsingSlice(b0, b1, len, iter) { 111cb0ef41Sopenharmony_ci for (let i = 0; i < iter; i++) 121cb0ef41Sopenharmony_ci Buffer.compare(b0.slice(1, len), b1.slice(1, len)); 131cb0ef41Sopenharmony_ci} 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_cifunction compareUsingOffset(b0, b1, len, iter) { 161cb0ef41Sopenharmony_ci for (let i = 0; i < iter; i++) 171cb0ef41Sopenharmony_ci b0.compare(b1, 1, len, 1, len); 181cb0ef41Sopenharmony_ci} 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cifunction main({ n, size, method }) { 211cb0ef41Sopenharmony_ci const fn = method === 'slice' ? compareUsingSlice : compareUsingOffset; 221cb0ef41Sopenharmony_ci bench.start(); 231cb0ef41Sopenharmony_ci fn(Buffer.alloc(size, 'a'), 241cb0ef41Sopenharmony_ci Buffer.alloc(size, 'b'), 251cb0ef41Sopenharmony_ci size >> 1, 261cb0ef41Sopenharmony_ci n); 271cb0ef41Sopenharmony_ci bench.end(n); 281cb0ef41Sopenharmony_ci} 29