FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
benchmarks/src/main/java/org/lmdbjava/bench/LmdbJni.java at master · lmdbjava/benchmarks · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
lmdbjava
/
benchmarks
Public
Notifications
You must be signed in to change notification settings
Fork
22
Star
144
Code
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
benchmarks
/
src
/
main
/
java
/
org
/
lmdbjava
/
bench
/
LmdbJni.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
278 lines (240 loc) · 7.54 KB
Breadcrumbs
benchmarks
/
src
/
main
/
java
/
org
/
lmdbjava
/
bench
/
LmdbJni.java
Copy path
File metadata and controls
278 lines (240 loc) · 7.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
* Copyright © 2016-2025 The LmdbJava Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
lmdbjava
.
bench
;
import
static
java
.
lang
.
Boolean
.
TRUE
;
import
static
java
.
lang
.
System
.
setProperty
;
import
static
java
.
nio
.
ByteBuffer
.
allocateDirect
;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
MILLISECONDS
;
import
static
org
.
fusesource
.
lmdbjni
.
DirectBuffer
.
DISABLE_BOUNDS_CHECKS_PROP_NAME
;
import
static
org
.
lmdbjava
.
MaskedFlag
.
mask
;
import
static
org
.
lmdbjava
.
bench
.
CommonLmdbJava
.
POSIX_MODE
;
import
static
org
.
lmdbjava
.
bench
.
CommonLmdbJava
.
dbiFlags
;
import
static
org
.
lmdbjava
.
bench
.
CommonLmdbJava
.
envFlags
;
import
static
org
.
lmdbjava
.
bench
.
CommonLmdbJava
.
mapSize
;
import
static
org
.
openjdk
.
jmh
.
annotations
.
Level
.
Invocation
;
import
static
org
.
openjdk
.
jmh
.
annotations
.
Level
.
Trial
;
import
static
org
.
openjdk
.
jmh
.
annotations
.
Mode
.
SampleTime
;
import
static
org
.
openjdk
.
jmh
.
annotations
.
Scope
.
Benchmark
;
import
java
.
io
.
IOException
;
import
net
.
jpountz
.
xxhash
.
StreamingXXHash64
;
import
net
.
jpountz
.
xxhash
.
XXHashFactory
;
import
org
.
fusesource
.
lmdbjni
.
BufferCursor
;
import
org
.
fusesource
.
lmdbjni
.
Database
;
import
org
.
fusesource
.
lmdbjni
.
DirectBuffer
;
import
org
.
fusesource
.
lmdbjni
.
Env
;
import
org
.
fusesource
.
lmdbjni
.
Transaction
;
import
org
.
lmdbjava
.
DbiFlags
;
import
org
.
lmdbjava
.
EnvFlags
;
import
org
.
openjdk
.
jmh
.
annotations
.
Benchmark
;
import
org
.
openjdk
.
jmh
.
annotations
.
BenchmarkMode
;
import
org
.
openjdk
.
jmh
.
annotations
.
Fork
;
import
org
.
openjdk
.
jmh
.
annotations
.
Measurement
;
import
org
.
openjdk
.
jmh
.
annotations
.
OutputTimeUnit
;
import
org
.
openjdk
.
jmh
.
annotations
.
Param
;
import
org
.
openjdk
.
jmh
.
annotations
.
Setup
;
import
org
.
openjdk
.
jmh
.
annotations
.
State
;
import
org
.
openjdk
.
jmh
.
annotations
.
TearDown
;
import
org
.
openjdk
.
jmh
.
annotations
.
Warmup
;
import
org
.
openjdk
.
jmh
.
infra
.
BenchmarkParams
;
import
org
.
openjdk
.
jmh
.
infra
.
Blackhole
;
@
OutputTimeUnit
(
MILLISECONDS
)
@
Fork
(
1
)
@
Warmup
(
iterations
=
3
)
@
Measurement
(
iterations
=
3
)
@
BenchmarkMode
(
SampleTime
)
public
class
LmdbJni
{
@
Benchmark
public
void
readCrc
(
final
Reader
r
,
final
Blackhole
bh
) {
r
.
crc
.
reset
();
bh
.
consume
(
r
.
c
.
first
());
do
{
r
.
c
.
keyBuffer
().
getBytes
(
0
,
r
.
keyBytes
,
0
,
r
.
keySize
);
r
.
c
.
valBuffer
().
getBytes
(
0
,
r
.
valBytes
,
0
,
r
.
valSize
);
r
.
crc
.
update
(
r
.
keyBytes
);
r
.
crc
.
update
(
r
.
valBytes
);
}
while
(
r
.
c
.
next
());
bh
.
consume
(
r
.
crc
.
getValue
());
}
@
Benchmark
public
void
readKey
(
final
Reader
r
,
final
Blackhole
bh
) {
for
(
final
int
key
:
r
.
keys
) {
if
(
r
.
intKey
) {
r
.
wkb
.
putInt
(
0
,
key
);
}
else
{
r
.
wkb
.
putStringWithoutLengthUtf8
(
0
,
r
.
padKey
(
key
));
}
r
.
c
.
keyWrite
(
r
.
wkb
);
bh
.
consume
(
r
.
c
.
seekKey
());
bh
.
consume
(
r
.
c
.
valBuffer
());
}
}
@
Benchmark
public
void
readRev
(
final
Reader
r
,
final
Blackhole
bh
) {
bh
.
consume
(
r
.
c
.
last
());
do
{
bh
.
consume
(
r
.
c
.
valBuffer
());
}
while
(
r
.
c
.
prev
());
}
@
Benchmark
public
void
readSeq
(
final
Reader
r
,
final
Blackhole
bh
) {
bh
.
consume
(
r
.
c
.
first
());
do
{
bh
.
consume
(
r
.
c
.
valBuffer
());
}
while
(
r
.
c
.
next
());
}
@
Benchmark
public
void
readXxh64
(
final
Reader
r
,
final
Blackhole
bh
) {
r
.
xxh
.
reset
();
bh
.
consume
(
r
.
c
.
first
());
do
{
r
.
c
.
keyBuffer
().
getBytes
(
0
,
r
.
keyBytes
,
0
,
r
.
keySize
);
r
.
c
.
valBuffer
().
getBytes
(
0
,
r
.
valBytes
,
0
,
r
.
valSize
);
r
.
xxh
.
update
(
r
.
keyBytes
,
0
,
r
.
keySize
);
r
.
xxh
.
update
(
r
.
valBytes
,
0
,
r
.
valSize
);
}
while
(
r
.
c
.
next
());
bh
.
consume
(
r
.
xxh
.
getValue
());
}
@
Benchmark
public
void
write
(
final
Writer
w
,
final
Blackhole
bh
) {
w
.
write
();
}
@
State
(
value
=
Benchmark
)
public
static
class
CommonLmdbJni
extends
Common
{
Database
db
;
Env
env
;
/**
* CRC scratch (memory-mapped MDB can't return a byte[] or ByteBuffer).
*/
byte
[]
keyBytes
;
/**
* CRC scratch (memory-mapped MDB can't return a byte[] or ByteBuffer).
*/
byte
[]
valBytes
;
/**
* CRC scratch (memory-mapped MDB can't return a byte[] or ByteBuffer).
*/
DirectBuffer
wkb
;
/**
* Whether {@link EnvFlags#MDB_WRITEMAP} is used.
*/
@
Param
(
"true"
)
boolean
writeMap
;
/**
* Writable value buffer.
*/
DirectBuffer
wvb
;
static
{
setProperty
(
DISABLE_BOUNDS_CHECKS_PROP_NAME
,
TRUE
.
toString
());
}
public
void
setup
(
final
BenchmarkParams
b
,
final
boolean
sync
)
throws
IOException
{
super
.
setup
(
b
);
wkb
=
new
DirectBuffer
(
allocateDirect
(
keySize
));
wvb
=
new
DirectBuffer
(
allocateDirect
(
valSize
));
keyBytes
=
new
byte
[
keySize
];
valBytes
=
new
byte
[
valSize
];
final
EnvFlags
[]
envFlags
=
envFlags
(
writeMap
,
sync
);
env
=
new
Env
();
env
.
setMapSize
(
mapSize
(
num
,
valSize
));
env
.
setMaxDbs
(
1
);
env
.
setMaxReaders
(
2
);
env
.
open
(
tmp
.
getAbsolutePath
(),
mask
(
envFlags
),
POSIX_MODE
);
try
(
Transaction
tx
=
env
.
createWriteTransaction
()) {
final
DbiFlags
[]
flags
=
dbiFlags
(
intKey
);
db
=
env
.
openDatabase
(
tx
,
"db"
,
mask
(
flags
));
tx
.
commit
();
}
}
@
Override
public
void
teardown
()
throws
IOException
{
reportSpaceBeforeClose
();
env
.
close
();
super
.
teardown
();
}
void
write
() {
try
(
Transaction
tx
=
env
.
createWriteTransaction
()) {
try
(
BufferCursor
c
=
db
.
bufferCursor
(
tx
);) {
final
int
rndByteMax
=
RND_MB
.
length
-
valSize
;
int
rndByteOffset
=
0
;
for
(
final
int
key
:
keys
) {
if
(
intKey
) {
wkb
.
putInt
(
0
,
key
);
}
else
{
wkb
.
putStringWithoutLengthUtf8
(
0
,
padKey
(
key
));
}
if
(
valRandom
) {
wvb
.
putBytes
(
0
,
RND_MB
,
rndByteOffset
,
valSize
);
rndByteOffset
+=
valSize
;
if
(
rndByteOffset
>=
rndByteMax
) {
rndByteOffset
=
0
;
}
}
else
{
wvb
.
putInt
(
0
,
key
);
}
c
.
keyWrite
(
wkb
);
c
.
valWrite
(
wvb
);
if
(
sequential
) {
c
.
append
();
}
else
{
c
.
overwrite
();
}
}
}
tx
.
commit
();
}
}
}
@
State
(
Benchmark
)
public
static
class
Reader
extends
CommonLmdbJni
{
BufferCursor
c
;
Transaction
tx
;
StreamingXXHash64
xxh
;
@
Setup
(
Trial
)
@
Override
public
void
setup
(
final
BenchmarkParams
b
)
throws
IOException
{
super
.
setup
(
b
,
false
);
super
.
write
();
tx
=
env
.
createReadTransaction
();
c
=
db
.
bufferCursor
(
tx
);
xxh
=
XXHashFactory
.
fastestJavaInstance
().
newStreamingHash64
(
0
);
}
@
TearDown
(
Trial
)
@
Override
public
void
teardown
()
throws
IOException
{
c
.
close
();
tx
.
abort
();
super
.
teardown
();
}
}
@
State
(
Benchmark
)
public
static
class
Writer
extends
CommonLmdbJni
{
/**
* Whether {@link EnvFlags#MDB_NOSYNC} is used.
*/
@
Param
(
"false"
)
boolean
sync
;
@
Setup
(
Invocation
)
@
Override
public
void
setup
(
final
BenchmarkParams
b
)
throws
IOException
{
super
.
setup
(
b
,
sync
);
}
@
TearDown
(
Invocation
)
@
Override
public
void
teardown
()
throws
IOException
{
super
.
teardown
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL