|
21 | 21 | // MODULES // |
22 | 22 |
|
23 | 23 | var bench = require( '@stdlib/bench' ); |
| 24 | +var DataType = require( './../../../dtype-ctor' ); |
| 25 | +var structFactory = require( '@stdlib/dstructs/struct' ); |
24 | 26 | var pkg = require( './../package.json' ).name; |
25 | 27 | var bytesPerElement = require( './../lib' ); |
26 | 28 |
|
27 | 29 |
|
28 | 30 | // MAIN // |
29 | 31 |
|
30 | | -bench( pkg, function benchmark( b ) { |
| 32 | +bench( pkg+'::string', function benchmark( b ) { |
31 | 33 | var dtypes; |
32 | 34 | var dtype; |
33 | 35 | var out; |
@@ -63,3 +65,125 @@ bench( pkg, function benchmark( b ) { |
63 | 65 | b.pass( 'benchmark finished' ); |
64 | 66 | b.end(); |
65 | 67 | }); |
| 68 | + |
| 69 | +bench( pkg+'::struct', function benchmark( b ) { |
| 70 | + var schemas; |
| 71 | + var dtypes; |
| 72 | + var dtype; |
| 73 | + var out; |
| 74 | + var i; |
| 75 | + |
| 76 | + schemas = [ |
| 77 | + [ |
| 78 | + { |
| 79 | + 'name': 'foo', |
| 80 | + 'type': 'float64' |
| 81 | + } |
| 82 | + ], |
| 83 | + [ |
| 84 | + { |
| 85 | + 'name': 'foo', |
| 86 | + 'type': 'float32' |
| 87 | + } |
| 88 | + ] |
| 89 | + ]; |
| 90 | + |
| 91 | + dtypes = [ |
| 92 | + structFactory( schemas[ 0 ] ), |
| 93 | + structFactory( schemas[ 1 ] ) |
| 94 | + ]; |
| 95 | + |
| 96 | + b.tic(); |
| 97 | + for ( i = 0; i < b.iterations; i++ ) { |
| 98 | + dtype = dtypes[ i%dtypes.length ]; |
| 99 | + out = bytesPerElement( dtype ); |
| 100 | + if ( out !== out ) { |
| 101 | + b.fail( 'should not return NaN' ); |
| 102 | + } |
| 103 | + } |
| 104 | + b.toc(); |
| 105 | + if ( out !== out ) { |
| 106 | + b.fail( 'should not return NaN' ); |
| 107 | + } |
| 108 | + b.pass( 'benchmark finished' ); |
| 109 | + b.end(); |
| 110 | +}); |
| 111 | + |
| 112 | +bench( pkg+'::data_type_instance,string', function benchmark( b ) { |
| 113 | + var dtypes; |
| 114 | + var dtype; |
| 115 | + var out; |
| 116 | + var i; |
| 117 | + |
| 118 | + dtypes = [ |
| 119 | + new DataType( 'float64' ), |
| 120 | + new DataType( 'float32' ), |
| 121 | + new DataType( 'int8' ), |
| 122 | + new DataType( 'uint8' ), |
| 123 | + new DataType( 'uint8c' ), |
| 124 | + new DataType( 'int16' ), |
| 125 | + new DataType( 'uint16' ), |
| 126 | + new DataType( 'int32' ), |
| 127 | + new DataType( 'uint32' ), |
| 128 | + new DataType( 'binary' ), |
| 129 | + new DataType( 'generic' ) |
| 130 | + ]; |
| 131 | + |
| 132 | + b.tic(); |
| 133 | + for ( i = 0; i < b.iterations; i++ ) { |
| 134 | + dtype = dtypes[ i%dtypes.length ]; |
| 135 | + out = bytesPerElement( dtype ); |
| 136 | + if ( out !== out ) { |
| 137 | + b.fail( 'should not return NaN' ); |
| 138 | + } |
| 139 | + } |
| 140 | + b.toc(); |
| 141 | + if ( out !== out ) { |
| 142 | + b.fail( 'should not return NaN' ); |
| 143 | + } |
| 144 | + b.pass( 'benchmark finished' ); |
| 145 | + b.end(); |
| 146 | +}); |
| 147 | + |
| 148 | +bench( pkg+'::data_type_instance,struct', function benchmark( b ) { |
| 149 | + var schemas; |
| 150 | + var dtypes; |
| 151 | + var dtype; |
| 152 | + var out; |
| 153 | + var i; |
| 154 | + |
| 155 | + schemas = [ |
| 156 | + [ |
| 157 | + { |
| 158 | + 'name': 'foo', |
| 159 | + 'type': 'float64' |
| 160 | + } |
| 161 | + ], |
| 162 | + [ |
| 163 | + { |
| 164 | + 'name': 'foo', |
| 165 | + 'type': 'float32' |
| 166 | + } |
| 167 | + ] |
| 168 | + ]; |
| 169 | + |
| 170 | + dtypes = [ |
| 171 | + new DataType( structFactory( schemas[ 0 ] ) ), |
| 172 | + new DataType( structFactory( schemas[ 1 ] ) ) |
| 173 | + ]; |
| 174 | + |
| 175 | + b.tic(); |
| 176 | + for ( i = 0; i < b.iterations; i++ ) { |
| 177 | + dtype = dtypes[ i%dtypes.length ]; |
| 178 | + out = bytesPerElement( dtype ); |
| 179 | + if ( out !== out ) { |
| 180 | + b.fail( 'should not return NaN' ); |
| 181 | + } |
| 182 | + } |
| 183 | + b.toc(); |
| 184 | + if ( out !== out ) { |
| 185 | + b.fail( 'should not return NaN' ); |
| 186 | + } |
| 187 | + b.pass( 'benchmark finished' ); |
| 188 | + b.end(); |
| 189 | +}); |
0 commit comments