Skip to content

Commit 465ccdd

Browse files
committed
jmh related logic moved to external folder
1 parent 97f177d commit 465ccdd

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

jbbp/src/main/java/com/igormaznitsa/jbbp/utils/JBBPDslBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ protected static String assertNameIfNotNull(final String name) {
6767
if (name != null) {
6868
for (int i = 0; i < name.length(); i++) {
6969
final char c = name.charAt(i);
70-
if (i == 0 && Character.isDigit(c)) {
70+
if (i == 0 && (Character.isDigit(c))) {
7171
throw new IllegalArgumentException("Digit can't be first char");
7272
}
73-
if (!Character.isLetterOrDigit(c)) {
73+
if (!Character.isLetterOrDigit(c) && c != '_') {
7474
throw new IllegalArgumentException("Only letters and digits allowed: " + name);
7575
}
7676
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2017 Igor Maznitsa.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.igormaznitsa.jbbp.benchmarks;
18+
19+
import com.igormaznitsa.jbbp.JBBPParser;
20+
import com.igormaznitsa.jbbp.io.JBBPBitInputStream;
21+
import com.igormaznitsa.jbbp.mapper.Bin;
22+
import com.igormaznitsa.jbbp.mapper.BinType;
23+
import com.igormaznitsa.jbbp.utils.TargetSources;
24+
import org.openjdk.jmh.annotations.Benchmark;
25+
26+
import java.io.ByteArrayInputStream;
27+
import java.io.IOException;
28+
import java.util.Random;
29+
30+
31+
/**
32+
* Test set to check productivity of different work modes with parsing data of the same data set.
33+
*/
34+
public class JBBP_Benchmark {
35+
36+
private static final JBBPParser parser = JBBPParser.prepare("ubyte value; data [(value>>1)*(value+3)]{ bit:3 a; bit:3 b; bit:2 c; skip:1; }");
37+
38+
private static final Random RND = new Random(12345);
39+
40+
private static final byte[] DATA;
41+
42+
static {
43+
final int val = 201;
44+
DATA = new byte[1 + ((val >> 1) * (val + 3)) * 2];
45+
RND.nextBytes(DATA);
46+
DATA[0] = (byte) val;
47+
}
48+
49+
@Benchmark
50+
public void measureParse_DynamicAndMapping() throws IOException {
51+
parser.parse(DATA).mapTo(Data.class);
52+
}
53+
54+
@Benchmark
55+
public void measureParse_Dynamic() throws IOException {
56+
parser.parse(DATA);
57+
}
58+
59+
@Benchmark
60+
public void measureParse_Static() throws IOException {
61+
new JBBPBenchmarkParser().read(new JBBPBitInputStream(new ByteArrayInputStream(DATA)));
62+
}
63+
64+
public static class InData {
65+
@Bin(name = "a", type = BinType.BIT)
66+
public byte a;
67+
@Bin(name = "b", type = BinType.BIT)
68+
public byte b;
69+
@Bin(name = "c", type = BinType.BIT)
70+
public byte c;
71+
}
72+
73+
public static class Data {
74+
@Bin(name = "value", type = BinType.UBYTE)
75+
public int value;
76+
77+
@Bin(name = "data")
78+
public InData[] data;
79+
}
80+
}

0 commit comments

Comments
 (0)