11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 51cb0ef41Sopenharmony_ci encoding: [ 61cb0ef41Sopenharmony_ci '', 'utf8', 'ascii', 'hex', 'utf16le', 'latin1', 71cb0ef41Sopenharmony_ci ], 81cb0ef41Sopenharmony_ci args: [ '', 'offset', 'offset+length' ], 91cb0ef41Sopenharmony_ci len: [2048], 101cb0ef41Sopenharmony_ci n: [1e6], 111cb0ef41Sopenharmony_ci}); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cifunction main({ len, n, encoding, args }) { 141cb0ef41Sopenharmony_ci let string; 151cb0ef41Sopenharmony_ci let start = 0; 161cb0ef41Sopenharmony_ci const buf = Buffer.allocUnsafe(len); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci switch (args) { 191cb0ef41Sopenharmony_ci case 'offset': 201cb0ef41Sopenharmony_ci string = 'a'.repeat(Math.floor(len / 2)); 211cb0ef41Sopenharmony_ci start = len - string.length; 221cb0ef41Sopenharmony_ci if (encoding) { 231cb0ef41Sopenharmony_ci bench.start(); 241cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) { 251cb0ef41Sopenharmony_ci buf.write(string, start, encoding); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci bench.end(n); 281cb0ef41Sopenharmony_ci } else { 291cb0ef41Sopenharmony_ci bench.start(); 301cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) { 311cb0ef41Sopenharmony_ci buf.write(string, start); 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci bench.end(n); 341cb0ef41Sopenharmony_ci } 351cb0ef41Sopenharmony_ci break; 361cb0ef41Sopenharmony_ci case 'offset+length': 371cb0ef41Sopenharmony_ci string = 'a'.repeat(len); 381cb0ef41Sopenharmony_ci if (encoding) { 391cb0ef41Sopenharmony_ci bench.start(); 401cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) { 411cb0ef41Sopenharmony_ci buf.write(string, 0, buf.length, encoding); 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci bench.end(n); 441cb0ef41Sopenharmony_ci } else { 451cb0ef41Sopenharmony_ci bench.start(); 461cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) { 471cb0ef41Sopenharmony_ci buf.write(string, 0, buf.length); 481cb0ef41Sopenharmony_ci } 491cb0ef41Sopenharmony_ci bench.end(n); 501cb0ef41Sopenharmony_ci } 511cb0ef41Sopenharmony_ci break; 521cb0ef41Sopenharmony_ci default: 531cb0ef41Sopenharmony_ci string = 'a'.repeat(len); 541cb0ef41Sopenharmony_ci if (encoding) { 551cb0ef41Sopenharmony_ci bench.start(); 561cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) { 571cb0ef41Sopenharmony_ci buf.write(string, encoding); 581cb0ef41Sopenharmony_ci } 591cb0ef41Sopenharmony_ci bench.end(n); 601cb0ef41Sopenharmony_ci } else { 611cb0ef41Sopenharmony_ci bench.start(); 621cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) { 631cb0ef41Sopenharmony_ci buf.write(string); 641cb0ef41Sopenharmony_ci } 651cb0ef41Sopenharmony_ci bench.end(n); 661cb0ef41Sopenharmony_ci } 671cb0ef41Sopenharmony_ci } 681cb0ef41Sopenharmony_ci} 69