File tree Expand file tree Collapse file tree 4 files changed +119
-0
lines changed Expand file tree Collapse file tree 4 files changed +119
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common.js' ) ;
3+ const {
4+ Blob,
5+ } = require ( 'node:buffer' ) ;
6+ const assert = require ( 'assert' ) ;
7+
8+ const bench = common . createBenchmark ( main , {
9+ n : [ 50e3 ] ,
10+ } ) ;
11+
12+ let _cloneResult ;
13+
14+ function main ( { n } ) {
15+ bench . start ( ) ;
16+ for ( let i = 0 ; i < n ; ++ i )
17+ _cloneResult = structuredClone ( new Blob ( [ 'hello' ] ) ) ;
18+ bench . end ( n ) ;
19+
20+ // Avoid V8 deadcode (elimination)
21+ assert . ok ( _cloneResult ) ;
22+ }
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common.js' ) ;
3+ const {
4+ Blob,
5+ } = require ( 'node:buffer' ) ;
6+ const assert = require ( 'assert' ) ;
7+
8+ const options = {
9+ flags : [ '--expose-internals' ] ,
10+ } ;
11+
12+ const bench = common . createBenchmark ( main , {
13+ n : [ 50e3 ] ,
14+ kind : [
15+ 'Blob' ,
16+ 'createBlob' ,
17+ ] ,
18+ } , options ) ;
19+
20+ let _blob ;
21+ let _createBlob ;
22+
23+ function main ( { n, kind } ) {
24+ switch ( kind ) {
25+ case 'Blob' : {
26+ bench . start ( ) ;
27+ for ( let i = 0 ; i < n ; ++ i )
28+ _blob = new Blob ( [ 'hello' ] ) ;
29+ bench . end ( n ) ;
30+
31+ // Avoid V8 deadcode (elimination)
32+ assert . ok ( _blob ) ;
33+ break ;
34+ } case 'createBlob' : {
35+ const { createBlob } = require ( 'internal/blob' ) ;
36+ const reusableBlob = new Blob ( [ 'hello' ] ) ;
37+ bench . start ( ) ;
38+ for ( let i = 0 ; i < n ; ++ i )
39+ _createBlob = createBlob ( reusableBlob , reusableBlob . size ) ;
40+ bench . end ( n ) ;
41+
42+ // Avoid V8 deadcode (elimination)
43+ assert . ok ( _createBlob ) ;
44+ break ;
45+ } default :
46+ throw new Error ( 'Invalid kind' ) ;
47+ }
48+ }
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common.js' ) ;
3+ const { Blob, resolveObjectURL } = require ( 'node:buffer' ) ;
4+ const assert = require ( 'assert' ) ;
5+
6+ const bench = common . createBenchmark ( main , {
7+ n : [ 50e3 ] ,
8+ } ) ;
9+
10+ let _resolveObjectURL ;
11+
12+ function main ( { n } ) {
13+ const blob = new Blob ( [ 'hello' ] ) ;
14+ const id = URL . createObjectURL ( blob ) ;
15+ bench . start ( ) ;
16+ for ( let i = 0 ; i < n ; ++ i )
17+ _resolveObjectURL = resolveObjectURL ( id ) ;
18+ bench . end ( n ) ;
19+
20+ // Avoid V8 deadcode (elimination)
21+ assert . ok ( _resolveObjectURL ) ;
22+ }
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common.js' ) ;
3+ const { Blob } = require ( 'node:buffer' ) ;
4+ const assert = require ( 'assert' ) ;
5+
6+ const bench = common . createBenchmark ( main , {
7+ n : [ 50e3 ] ,
8+ dataSize : [
9+ 5 ,
10+ 30 * 1024 ,
11+ ] ,
12+ } ) ;
13+
14+ let _sliceResult ;
15+
16+ function main ( { n, dataSize } ) {
17+ const data = 'a' . repeat ( dataSize ) ;
18+ const reusableBlob = new Blob ( [ data ] ) ;
19+
20+ bench . start ( ) ;
21+ for ( let i = 0 ; i < n ; ++ i )
22+ _sliceResult = reusableBlob . slice ( 0 , Math . floor ( data . length / 2 ) ) ;
23+ bench . end ( n ) ;
24+
25+ // Avoid V8 deadcode (elimination)
26+ assert . ok ( _sliceResult ) ;
27+ }
You can’t perform that action at this time.
0 commit comments