22var common = require ( '../common' ) ;
33
44var bench = common . createBenchmark ( main , {
5- encoding : [ 'utf8' , 'base64' ] ,
5+ encoding : [ 'utf8' , 'base64' , 'buffer' ] ,
66 len : [ 1 , 2 , 4 , 16 , 64 , 256 ] , // x16
77 n : [ 5e6 ]
88} ) ;
@@ -21,21 +21,27 @@ function main(conf) {
2121 var encoding = conf . encoding ;
2222
2323 var strings = [ ] ;
24- for ( var string of chars ) {
25- // Strings must be built differently, depending on encoding
26- var data = buildString ( string , len ) ;
27- if ( encoding === 'utf8' ) {
28- strings . push ( data ) ;
29- } else if ( encoding === 'base64' ) {
30- // Base64 strings will be much longer than their UTF8 counterparts
31- strings . push ( Buffer . from ( data , 'utf8' ) . toString ( 'base64' ) ) ;
24+ var results ;
25+ if ( encoding === 'buffer' ) {
26+ strings = [ Buffer . alloc ( len * 16 , 'a' ) ] ;
27+ results = [ len * 16 ] ;
28+ } else {
29+ for ( var string of chars ) {
30+ // Strings must be built differently, depending on encoding
31+ var data = buildString ( string , len ) ;
32+ if ( encoding === 'utf8' ) {
33+ strings . push ( data ) ;
34+ } else if ( encoding === 'base64' ) {
35+ // Base64 strings will be much longer than their UTF8 counterparts
36+ strings . push ( Buffer . from ( data , 'utf8' ) . toString ( 'base64' ) ) ;
37+ }
3238 }
33- }
3439
35- // Check the result to ensure it is *properly* optimized
36- var results = strings . map ( function ( val ) {
37- return Buffer . byteLength ( val , encoding ) ;
38- } ) ;
40+ // Check the result to ensure it is *properly* optimized
41+ results = strings . map ( function ( val ) {
42+ return Buffer . byteLength ( val , encoding ) ;
43+ } ) ;
44+ }
3945
4046 bench . start ( ) ;
4147 for ( var i = 0 ; i < n ; i ++ ) {