@@ -9,8 +9,7 @@ const bench = common.createBenchmark(main, {
9
9
api : [ 'legacy' , 'stream' ]
10
10
} ) ;
11
11
12
- function main ( conf ) {
13
- var api = conf . api ;
12
+ function main ( { api, cipher, type, len, writes } ) {
14
13
if ( api === 'stream' && / ^ v 0 \. [ 0 - 8 ] \. / . test ( process . version ) ) {
15
14
console . error ( 'Crypto streams not available until v0.10' ) ;
16
15
// use the legacy, just so that we can compare them.
@@ -33,33 +32,33 @@ function main(conf) {
33
32
// alice_secret and bob_secret should be the same
34
33
assert ( alice_secret === bob_secret ) ;
35
34
36
- const alice_cipher = crypto . createCipher ( conf . cipher , alice_secret ) ;
37
- const bob_cipher = crypto . createDecipher ( conf . cipher , bob_secret ) ;
35
+ const alice_cipher = crypto . createCipher ( cipher , alice_secret ) ;
36
+ const bob_cipher = crypto . createDecipher ( cipher , bob_secret ) ;
38
37
39
38
var message ;
40
39
var encoding ;
41
- switch ( conf . type ) {
40
+ switch ( type ) {
42
41
case 'asc' :
43
- message = 'a' . repeat ( conf . len ) ;
42
+ message = 'a' . repeat ( len ) ;
44
43
encoding = 'ascii' ;
45
44
break ;
46
45
case 'utf' :
47
- message = 'ü' . repeat ( conf . len / 2 ) ;
46
+ message = 'ü' . repeat ( len / 2 ) ;
48
47
encoding = 'utf8' ;
49
48
break ;
50
49
case 'buf' :
51
- message = Buffer . alloc ( conf . len , 'b' ) ;
50
+ message = Buffer . alloc ( len , 'b' ) ;
52
51
break ;
53
52
default :
54
- throw new Error ( `unknown message type: ${ conf . type } ` ) ;
53
+ throw new Error ( `unknown message type: ${ type } ` ) ;
55
54
}
56
55
57
56
const fn = api === 'stream' ? streamWrite : legacyWrite ;
58
57
59
58
// write data as fast as possible to alice, and have bob decrypt.
60
59
// use old API for comparison to v0.8
61
60
bench . start ( ) ;
62
- fn ( alice_cipher , bob_cipher , message , encoding , conf . writes ) ;
61
+ fn ( alice_cipher , bob_cipher , message , encoding , writes ) ;
63
62
}
64
63
65
64
function streamWrite ( alice , bob , message , encoding , writes ) {
0 commit comments