11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 61cb0ef41Sopenharmony_ci type: [ 71cb0ef41Sopenharmony_ci 'fast-alloc', 81cb0ef41Sopenharmony_ci 'fast-alloc-fill', 91cb0ef41Sopenharmony_ci 'fast-allocUnsafe', 101cb0ef41Sopenharmony_ci 'slow-allocUnsafe', 111cb0ef41Sopenharmony_ci ], 121cb0ef41Sopenharmony_ci len: [10, 1024, 4096, 8192], 131cb0ef41Sopenharmony_ci n: [6e5], 141cb0ef41Sopenharmony_ci}); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cifunction main({ len, n, type }) { 171cb0ef41Sopenharmony_ci let fn, i; 181cb0ef41Sopenharmony_ci switch (type) { 191cb0ef41Sopenharmony_ci case 'fast-alloc': 201cb0ef41Sopenharmony_ci fn = Buffer.alloc; 211cb0ef41Sopenharmony_ci break; 221cb0ef41Sopenharmony_ci case 'fast-alloc-fill': 231cb0ef41Sopenharmony_ci bench.start(); 241cb0ef41Sopenharmony_ci for (i = 0; i < n; i++) { 251cb0ef41Sopenharmony_ci Buffer.alloc(len, 0); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci bench.end(n); 281cb0ef41Sopenharmony_ci return; 291cb0ef41Sopenharmony_ci case 'fast-allocUnsafe': 301cb0ef41Sopenharmony_ci fn = Buffer.allocUnsafe; 311cb0ef41Sopenharmony_ci break; 321cb0ef41Sopenharmony_ci case 'slow-allocUnsafe': 331cb0ef41Sopenharmony_ci fn = Buffer.allocUnsafeSlow; 341cb0ef41Sopenharmony_ci break; 351cb0ef41Sopenharmony_ci default: 361cb0ef41Sopenharmony_ci assert.fail('Should not get here'); 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci bench.start(); 401cb0ef41Sopenharmony_ci for (i = 0; i < n; i++) { 411cb0ef41Sopenharmony_ci fn(len); 421cb0ef41Sopenharmony_ci } 431cb0ef41Sopenharmony_ci bench.end(n); 441cb0ef41Sopenharmony_ci} 45