-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buffer: remove async tick and improve perf by 680%
- Loading branch information
Showing
2 changed files
with
33 additions
and
3 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,29 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const { Blob } = require('buffer'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
bytes: [0, 8, 128], | ||
n: [1e6], | ||
operation: ['text', 'arrayBuffer', 'stream'] | ||
}); | ||
|
||
function main({ 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': | ||
source.text(); | ||
break; | ||
case 'arrayBuffer': | ||
source.arrayBuffer(); | ||
break; | ||
case 'stream': | ||
source.stream(); | ||
break; | ||
} | ||
} | ||
bench.end(n); | ||
} |
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