-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: #44990 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const { Blob } = require('buffer'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
bytes: [128, 1024, 1024 ** 2], | ||
n: [1e6], | ||
operation: ['text', 'arrayBuffer'] | ||
}); | ||
|
||
async function run(n, bytes, operation) { | ||
const buff = Buffer.allocUnsafe(bytes); | ||
const source = new Blob(buff); | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
switch (operation) { | ||
case 'text': | ||
await source.text(); | ||
break; | ||
case 'arrayBuffer': | ||
await source.arrayBuffer(); | ||
break; | ||
} | ||
} | ||
bench.end(n); | ||
} | ||
|
||
function main(conf) { | ||
run(conf.n, conf.bytes, conf.operation).catch(console.log); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const runBenchmark = require('../common/benchmark'); | ||
|
||
runBenchmark('blob', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); |