@@ -4,7 +4,7 @@ import { benchmark, generateRandomKeys, generateSequentialKeys, randomString } f
44describe ( 'putSync()' , ( ) => {
55 const SMALL_DATASET = 100 ;
66
7- describe ( 'random keys - small key size (100 records)' , ( ) => {
7+ describe ( 'random keys - insert - small key size (100 records)' , ( ) => {
88 benchmark ( 'rocksdb' , {
99 setup ( ctx ) {
1010 ctx . data = generateRandomKeys ( SMALL_DATASET ) ;
@@ -28,7 +28,35 @@ describe('putSync()', () => {
2828 } ) ;
2929 } ) ;
3030
31- describe ( 'random keys - max 1978 lmdb key size (100 records)' , ( ) => {
31+ describe ( 'random keys - update - small key size (100 records)' , ( ) => {
32+ function setup ( ctx ) {
33+ const data = generateRandomKeys ( SMALL_DATASET ) ;
34+ for ( const key of data ) {
35+ ctx . db . putSync ( key , 'test-value' ) ;
36+ }
37+ ctx . data = data . sort ( ( ) => Math . random ( ) - 0.5 ) ;
38+ }
39+
40+ benchmark ( 'rocksdb' , {
41+ setup,
42+ bench ( { data, db } ) {
43+ for ( const key of data ) {
44+ db . putSync ( key , 'test-value-updated' ) ;
45+ }
46+ }
47+ } ) ;
48+
49+ benchmark ( 'lmdb' , {
50+ setup,
51+ bench ( { data, db } ) {
52+ for ( const key of data ) {
53+ db . putSync ( key , 'test-value-updated' ) ;
54+ }
55+ }
56+ } ) ;
57+ } ) ;
58+
59+ describe ( 'random keys - insert - max 1978 lmdb key size (100 records)' , ( ) => {
3260 benchmark ( 'rocksdb' , {
3361 setup ( ctx ) {
3462 ctx . data = generateRandomKeys ( SMALL_DATASET , 1978 ) ;
@@ -52,25 +80,59 @@ describe('putSync()', () => {
5280 } ) ;
5381 } ) ;
5482
55- describe ( 'sequential keys (100 records)' , ( ) => {
83+ describe ( 'random keys - update - max 1978 lmdb key size (100 records)' , ( ) => {
84+ function setup ( ctx ) {
85+ const data = generateRandomKeys ( SMALL_DATASET , 1978 ) ;
86+ for ( const key of data ) {
87+ ctx . db . putSync ( key , 'test-value' ) ;
88+ }
89+ ctx . data = data . sort ( ( ) => Math . random ( ) - 0.5 ) ;
90+ }
91+
92+ benchmark ( 'rocksdb' , {
93+ setup,
94+ bench ( { data, db } ) {
95+ for ( const key of data ) {
96+ db . putSync ( key , 'test-value-updated' ) ;
97+ }
98+ }
99+ } ) ;
100+
101+ benchmark ( 'lmdb' , {
102+ setup,
103+ bench ( { data, db } ) {
104+ for ( const key of data ) {
105+ db . putSync ( key , 'test-value-updated' ) ;
106+ }
107+ }
108+ } ) ;
109+ } ) ;
110+
111+ describe ( 'sequential keys - insert (100 records)' , ( ) => {
56112 benchmark ( 'rocksdb' , {
57113 setup ( ctx ) {
58114 ctx . data = generateSequentialKeys ( SMALL_DATASET ) ;
115+ for ( const key of ctx . data ) {
116+ ctx . db . putSync ( key , 'test-value' ) ;
117+ }
59118 } ,
60119 bench ( { data, db } ) {
61120 for ( const key of data ) {
62- db . putSync ( key , 'test-value' ) ;
121+ db . putSync ( key , 'test-value-updated ' ) ;
63122 }
64123 }
65124 } ) ;
66125
67126 benchmark ( 'lmdb' , {
68127 setup ( ctx ) {
69128 ctx . data = generateSequentialKeys ( SMALL_DATASET ) ;
129+ for ( const key of ctx . data ) {
130+ ctx . db . putSync ( key , 'test-value' ) ;
131+ }
70132 } ,
71133 bench ( { data, db } ) {
72134 for ( const key of data ) {
73- db . putSync ( key , 'test-value' ) ;
135+ db . putSync ( key , 'test-value-updated ' ) ;
74136 }
75137 }
76138 } ) ;
0 commit comments