@@ -6,30 +6,91 @@ process.on("unhandledRejection", (r) => {
66 debugger ;
77} ) ;
88
9- const testDB : JsonlDB < any > = new JsonlDB ( "test.jsonl" , {
10- autoCompress : { onClose : false } ,
11- throttleFS : {
12- intervalMs : 1000 ,
13- } ,
14- } ) ;
9+ async function testMedium ( ) {
10+ const testDB : JsonlDB < any > = new JsonlDB ( "test.jsonl" , {
11+ autoCompress : {
12+ sizeFactor : 2 ,
13+ sizeFactorMinimumSize : 5000 ,
14+ } ,
15+ ignoreReadErrors : true ,
16+ throttleFS : {
17+ intervalMs : 60000 ,
18+ maxBufferedCommands : 100 ,
19+ } ,
20+ } ) ;
21+
22+ function makeObj ( i : number ) {
23+ return {
24+ type : "state" ,
25+ common : {
26+ name : i . toString ( ) ,
27+ read : true ,
28+ write : true ,
29+ role : "state" ,
30+ type : "number" ,
31+ } ,
32+ native : { } ,
33+ } ;
34+ }
35+
36+ const NUM_PASSES = 10 ;
37+ const NUM_OBJECTS = 100000 ;
38+ let total : number = 0 ;
39+
40+ console . log ( "start test MEDIUM" ) ;
41+
42+ for ( let pass = 1 ; pass <= NUM_PASSES ; pass ++ ) {
43+ await fs . remove ( "test.jsonl" ) ;
44+
45+ await testDB . open ( ) ;
46+
47+ const start = Date . now ( ) ;
48+ for ( let i = 0 ; i < NUM_OBJECTS ; i ++ ) {
49+ const key = `benchmark.0.test${ i } ` ;
50+ const value = makeObj ( i ) ;
51+ testDB . set ( key , value ) ;
52+ }
53+
54+ await testDB . close ( ) ;
55+
56+ const time = Date . now ( ) - start ;
57+ total += time ;
58+
59+ process . stdout . write ( "." ) ;
60+ }
61+
62+ await fs . remove ( "test.jsonl" ) ;
63+
64+ process . stdout . write ( "\n\n" ) ;
65+
66+ console . log ( `${ NUM_PASSES } x, ${ NUM_OBJECTS } objects` ) ;
67+ console . log ( ` ${ ( total / NUM_PASSES ) . toFixed ( 2 ) } ms / attempt` ) ;
68+ console . log ( ` ${ ( ( NUM_OBJECTS / total ) * 1000 ) . toFixed ( 2 ) } changes/s` ) ;
69+ console . log ( ) ;
70+ console . log ( ) ;
71+ }
72+
73+ async function testSmall ( ) {
74+ const testDB : JsonlDB < any > = new JsonlDB ( "test.jsonl" , {
75+ autoCompress : { onClose : false } ,
76+ throttleFS : {
77+ intervalMs : 1000 ,
78+ } ,
79+ } ) ;
1580
16- ( async ( ) => {
1781 // add a shitton of values
1882 const NUM_PASSES = 10 ;
1983 const NUM_KEYS = 1000 ;
2084 const NUM_CHANGES = 100000 ;
2185 let total : number = 0 ;
2286
23- // console.time("open");
24- // console.timeEnd("open");
87+ console . log ( "start test SMALL" ) ;
2588
2689 for ( let pass = 1 ; pass <= NUM_PASSES ; pass ++ ) {
2790 await fs . remove ( "test.jsonl" ) ;
2891
2992 await testDB . open ( ) ;
3093
31- console . log ( `start ${ pass } ` ) ;
32-
3394 const start = Date . now ( ) ;
3495 for ( let i = 0 ; i < NUM_CHANGES ; i ++ ) {
3596 const key = `k${ padStart (
@@ -43,32 +104,29 @@ const testDB: JsonlDB<any> = new JsonlDB("test.jsonl", {
43104 testDB . set ( key , Math . random ( ) * 100 ) ;
44105 }
45106 }
46- console . log ( "close" ) ;
47107 await testDB . close ( ) ;
48108
49109 const time = Date . now ( ) - start ;
50110 total += time ;
51111
52- console . log ( `end ${ pass } ` ) ;
112+ process . stdout . write ( "." ) ;
53113 }
54- // console.time("close");
55- // await testDB.close();
56- // console.timeEnd("close");
114+
115+ await fs . remove ( "test.jsonl" ) ;
116+
117+ process . stdout . write ( "\n\n" ) ;
57118
58119 console . log ( `${ NUM_PASSES } x, ${ NUM_KEYS } keys, ${ NUM_CHANGES } changes` ) ;
59120 console . log ( ` ${ ( total / NUM_PASSES ) . toFixed ( 2 ) } ms / attempt` ) ;
60121 console . log ( ` ${ ( ( NUM_CHANGES / total ) * 1000 ) . toFixed ( 2 ) } changes/s` ) ;
122+ console . log ( ) ;
123+ console . log ( ) ;
124+ }
61125
62- process . exit ( 0 ) ;
63-
64- // console.time("open values");
65- // await testDB.open();
66- // console.log(testDB.size);
67- // console.timeEnd("open values");
68-
69- // await testDB.close();
70-
71- // await fs.remove("test.jsonl");
72- } ) ( ) . catch ( ( ) => {
73- /* ignore */
74- } ) ;
126+ testSmall ( )
127+ . then ( testMedium )
128+ . catch ( console . error )
129+ . finally ( ( ) => fs . remove ( "test.jsonl" ) )
130+ . catch ( ( ) => {
131+ /* ignore */
132+ } ) ;
0 commit comments