File tree Expand file tree Collapse file tree 1 file changed +26
-14
lines changed
packages/tinybench/benches Expand file tree Collapse file tree 1 file changed +26
-14
lines changed Original file line number Diff line number Diff line change 1
- import Benchmark from "benchmark" ;
2
1
import { withCodSpeed } from "../" ;
2
+ import { Bench } from "tinybench" ;
3
3
4
- const suite = withCodSpeed ( new Benchmark . Suite ( ) ) ;
4
+ const bench = withCodSpeed ( new Bench ( { time : 100 } ) ) ;
5
5
6
- suite
7
- . add ( "RegExp#test" , function ( ) {
8
- / o / . test ( "Hello World!" ) ;
6
+ bench
7
+ . add ( "switch 1" , ( ) => {
8
+ let a = 1 ;
9
+ let b = 2 ;
10
+ const c = a ;
11
+ a = b ;
12
+ b = c ;
9
13
} )
10
- . add ( "String#indexOf" , function ( ) {
11
- "Hello World!" . indexOf ( "o" ) > - 1 ;
12
- } )
13
- // add listeners
14
- . on ( "cycle" , function ( event : Benchmark . Event ) {
15
- console . log ( String ( event . target ) ) ;
16
- } )
17
- // run async
18
- . run ( { async : true } ) ;
14
+ . add ( "switch 2" , ( ) => {
15
+ let a = 1 ;
16
+ let b = 10 ;
17
+ a = b + a ;
18
+ b = a - b ;
19
+ a = b - a ;
20
+ } ) ;
21
+
22
+ await bench . run ( ) ;
23
+
24
+ console . table (
25
+ bench . tasks . map ( ( { name, result } ) => ( {
26
+ "Task Name" : name ,
27
+ "Average Time (ps)" : result ?. mean ? result . mean * 1000 : "N/A" ,
28
+ "Variance (ps)" : result ?. variance ? result . variance * 1000 : "N/A" ,
29
+ } ) )
30
+ ) ;
You can’t perform that action at this time.
0 commit comments