1 |
|
2 | /*
|
3 | Terminal Kit
|
4 |
|
5 | Copyright (c) 2009 - 2020 Cédric Ronvel
|
6 |
|
7 | The MIT License (MIT)
|
8 |
|
9 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
10 | of this software and associated documentation files (the "Software"), to deal
|
11 | in the Software without restriction, including without limitation the rights
|
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13 | copies of the Software, and to permit persons to whom the Software is
|
14 | furnished to do so, subject to the following conditions:
|
15 |
|
16 | The above copyright notice and this permission notice shall be included in all
|
17 | copies or substantial portions of the Software.
|
18 |
|
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
25 | SOFTWARE.
|
26 | */
|
27 |
|
28 | ;
|
29 |
|
30 |
|
31 |
|
32 | /* jshint unused:false */
|
33 | /* global describe, it, before, after */
|
34 |
|
35 |
|
36 |
|
37 | var size = 100 , loop = 1000000 ;
|
38 | var buf = new Buffer( size * 4 ) ;
|
39 |
|
40 |
|
41 |
|
42 | function test( method )
|
43 | {
|
44 | var i , j , t1 , t2 , values = [] ;
|
45 |
|
46 | // First prepare random values, we do not want that those operation pollute the benchmark
|
47 | for ( i = 0 ; i < loop ; i ++ )
|
48 | {
|
49 | values[ i ] = [] ;
|
50 | for ( j = 0 ; j < 10 ; j ++ )
|
51 | {
|
52 | values[ i ][ j ] = [ Math.floor( Math.random() * ( 1 << 30 ) ) , Math.floor( Math.random() * size ) ] ;
|
53 | }
|
54 | }
|
55 |
|
56 |
|
57 | // Now start the real benchmark
|
58 | t1 = new Date() ;
|
59 |
|
60 | for ( i = 0 ; i < loop ; i ++ )
|
61 | {
|
62 | // Partly unroll the loop, we dont want to benchmark the 'for' loop
|
63 | buf[ method ]( values[ i ][ 0 ][ 0 ] , values[ i ][ 0 ][ 1 ] ) ;
|
64 | buf[ method ]( values[ i ][ 1 ][ 0 ] , values[ i ][ 1 ][ 1 ] ) ;
|
65 | buf[ method ]( values[ i ][ 2 ][ 0 ] , values[ i ][ 2 ][ 1 ] ) ;
|
66 | buf[ method ]( values[ i ][ 3 ][ 0 ] , values[ i ][ 3 ][ 1 ] ) ;
|
67 | buf[ method ]( values[ i ][ 4 ][ 0 ] , values[ i ][ 4 ][ 1 ] ) ;
|
68 | buf[ method ]( values[ i ][ 5 ][ 0 ] , values[ i ][ 5 ][ 1 ] ) ;
|
69 | buf[ method ]( values[ i ][ 6 ][ 0 ] , values[ i ][ 6 ][ 1 ] ) ;
|
70 | buf[ method ]( values[ i ][ 7 ][ 0 ] , values[ i ][ 7 ][ 1 ] ) ;
|
71 | buf[ method ]( values[ i ][ 8 ][ 0 ] , values[ i ][ 8 ][ 1 ] ) ;
|
72 | buf[ method ]( values[ i ][ 9 ][ 0 ] , values[ i ][ 9 ][ 1 ] ) ;
|
73 | }
|
74 |
|
75 | t2 = new Date() ;
|
76 |
|
77 | // Display the result
|
78 | console.log( method , 'time:' , t2 - t1 , 'ms' ) ;
|
79 | }
|
80 |
|
81 |
|
82 |
|
83 | test( 'writeUInt32BE' ) ;
|
84 | test( 'writeUInt32LE' ) ;
|
85 | test( 'writeInt32BE' ) ;
|
86 | test( 'writeInt32LE' ) ;
|
87 |
|
88 | test( 'writeUInt32BE' ) ;
|
89 | test( 'writeUInt32LE' ) ;
|
90 | test( 'writeInt32BE' ) ;
|
91 | test( 'writeInt32LE' ) ;
|
92 |
|
93 |
|