Skip to content

Commit 3a95f2a

Browse files
authored
Merge pull request #4 from FasterXML/tatu/3-add-currency-test
Fix #3: add "Currency"/POJO test case for Floating-point decoding performance
2 parents 6726429 + 2358bf4 commit 3a95f2a

File tree

7 files changed

+139
-7
lines changed

7 files changed

+139
-7
lines changed

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,45 @@ This project contains simple set of performance micro-benchmarks, using excellen
88
Has been used since Jackson 2.4 to track performance changes: see various `results-pojo-2.x-home.txt`
99
files for numbers.
1010

11+
## Usage
12+
1113
Tests usually run with
1214

13-
profile-mediaitem.sh
15+
run-mediaitem.sh
1416

1517
or directly with something like
1618

17-
java -Xmx256m -jar target/microbenchmarks.jar ".*StdReadAfter.*PojoMediaItem.*" -wi 4 -w 1 -i 5 -r 1 -f 3 -t 1
19+
java -Xmx256m -jar target/microbenchmarks.jar ".*StdReadVanilla.*PojoMediaItem.*" -wi 4 -w 1 -i 5 -r 1 -f 3 -t 1
1820

1921
(see `results-pojo-2.13-home.txt` and others for specific invocations used for each group of numbers)
22+
23+
## Profiling
24+
25+
Can use
26+
27+
./profile-mediaitem.sh
28+
29+
to use basic JMH settings over runs.
30+
31+
## Test sets
32+
33+
### POJO: MediaItem
34+
35+
`MediaItem` POJO comes from: https://github.com/eishay/jvm-serializers tests suite.
36+
Test input generated is about 300 bytes as JSON, and between 200 and 500 bytes across other formats (converted from JSON which is considered canonical).
37+
38+
Settings to run tests include:
39+
40+
* Standard: java -Xmx256m -jar target/microbenchmarks.jar ".*StdReadVan.*PojoMedia.*" -wi 4 -w 1 -i 5 -r 1 -f 9 -t 1
41+
* Afterburner: java -Xmx256m -jar target/microbenchmarks.jar ".*StdReadAfter.*PojoMedia.*" -wi 4 -w 1 -i 5 -r 1 -f 9 -t
42+
1
43+
44+
### POJO: Currency (floating-point)
45+
46+
`Currency` POJO, and data file `./json/USD.json` (about 2kB) come from [Awesome JSON Datasets](https://github.com/jdorfman/awesome-json-datasets#currency).
47+
48+
Settings to run tests include:
49+
50+
* Default/JSON: java -Xmx256m -jar target/microbenchmarks.jar ".*Json.*readCurrencyPojoDefault.*" -wi 4 -w 1 -i 5 -r 1 -f 1 -t 1
51+
* FastFP/JSON: java -Xmx256m -jar target/microbenchmarks.jar ".*Json.*readCurrencyPojoFast.*" -wi 4 -w 1 -i 5 -r 1 -f 1 -t 1
52+
* All: java -Xmx256m -jar target/microbenchmarks.jar ".*readCurrencyPojo.*" -wi 4 -w 1 -i 5 -r 1 -f 1 -t 1

json/USD.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{"provider":"https://www.exchangerate-api.com",
2+
"terms":"https://www.exchangerate-api.com/terms",
3+
"base":"USD",
4+
"date":"2023-04-01",
5+
"time_last_updated":1680307201,
6+
"rates":{
7+
"USD":1,"AED":3.67,"AFN":86.8,"ALL":104.64,"AMD":389.34,"ANG":1.79,"AOA":510.31,"ARS":207.98,"AUD":1.49,"AWG":1.79,"AZN":1.7,"BAM":1.8,"BBD":2,"BDT":106.81,"BGN":1.8,"BHD":0.376,"BIF":2070.81,"BMD":1,"BND":1.33,"BOB":6.92,"BRL":5.08,"BSD":1,"BTN":82.19,"BWP":13.11,"BYN":2.68,"BZD":2,"CAD":1.35,"CDF":2049.44,"CHF":0.915,"CLP":790.44,"CNY":6.87,"COP":4649.49,"CRC":540.56,"CUP":24,"CVE":101.52,"CZK":21.62,"DJF":177.72,"DKK":6.87,"DOP":54.83,"DZD":135.57,"EGP":30.83,"ERN":15,"ETB":54.08,"EUR":0.921,"FJD":2.21,"FKP":0.81,"FOK":6.87,"GBP":0.81,"GEL":2.55,"GGP":0.81,"GHS":11.64,"GIP":0.81,"GMD":63.67,"GNF":8544.94,"GTQ":7.79,"GYD":211.26,"HKD":7.85,"HNL":24.61,"HRK":6.94,"HTG":155.07,"HUF":349.52,"IDR":14994.72,"ILS":3.6,"IMP":0.81,"INR":82.19,"IQD":1309.93,"IRR":42096.28,"ISK":136.34,"JEP":0.81,"JMD":150.96,"JOD":0.709,"JPY":132.92,"KES":132.34,"KGS":87.48,"KHR":4039.63,"KID":1.49,"KMF":452.95,"KRW":1304.07,"KWD":0.307,"KYD":0.833,"KZT":452.33,"LAK":16964.81,"LBP":15000,"LKR":324.88,"LRD":163.93,"LSL":17.78,"LYD":4.78,"MAD":10.22,"MDL":18.42,"MGA":4321.32,"MKD":56.71,"MMK":2097.95,"MNT":3524.66,"MOP":8.09,"MRU":34.22,"MUR":45.66,"MVR":15.43,"MWK":1031.23,"MXN":18.03,"MYR":4.42,"MZN":63.98,"NAD":17.78,"NGN":460.62,"NIO":36.55,"NOK":10.46,"NPR":131.51,"NZD":1.6,"OMR":0.384,"PAB":1,"PEN":3.76,"PGK":3.53,"PHP":54.3,"PKR":283.67,"PLN":4.3,"PYG":7151.72,"QAR":3.64,"RON":4.55,"RSD":107.87,"RUB":77.53,"RWF":1147.68,"SAR":3.75,"SBD":8.49,"SCR":13.29,"SDG":559.03,"SEK":10.37,"SGD":1.33,"SHP":0.81,"SLE":21.63,"SLL":21630.69,"SOS":568.44,"SRD":35.3,"SSP":856.64,"STN":22.56,"SYP":2521.05,"SZL":17.78,"THB":34.14,"TJS":10.91,"TMT":3.5,"TND":3.07,"TOP":2.36,"TRY":19.19,"TTD":6.75,"TVD":1.49,"TWD":30.46,"TZS":2342.17,"UAH":36.91,"UGX":3780.04,"UYU":38.73,"UZS":11414.47,"VES":24.53,"VND":23468.15,"VUV":119.05,"WST":2.71,"XAF":603.93,"XCD":2.7,"XDR":0.743,"XOF":603.93,"XPF":109.87,"YER":250.08,"ZAR":17.78,"ZMW":21.23,"ZWL":926.56
8+
}
9+
}

src/main/java/com/fasterxml/jackson/perf/ReadPerfBaseFullJackson.java

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import org.openjdk.jmh.infra.Blackhole;
88

99
import com.fasterxml.jackson.core.FormatSchema;
10+
import com.fasterxml.jackson.core.StreamReadFeature;
1011
import com.fasterxml.jackson.databind.*;
1112
import com.fasterxml.jackson.perf.data.InputConverter;
1213
import com.fasterxml.jackson.perf.data.InputData;
14+
import com.fasterxml.jackson.perf.model.Currency;
1315

1416
public abstract class ReadPerfBaseFullJackson<T>
1517
extends ReadPerfBaseBasicJackson<T>
@@ -20,12 +22,13 @@ public abstract class ReadPerfBaseFullJackson<T>
2022
protected final ObjectReader UNTYPED_READER;
2123
protected final ObjectReader NODE_READER;
2224

25+
protected final ObjectReader CURRENCY_READER_DEFAULT;
26+
protected final ObjectReader CURRENCY_READER_FAST;
27+
2328
protected ReadPerfBaseFullJackson(Class<T> type, InputConverter conv, ObjectMapper mapper)
2429
{
25-
super(type, conv, mapper);
26-
FULL_CONVERTER = conv;
27-
UNTYPED_READER = mapper.readerFor(Object.class);
28-
NODE_READER = mapper.readerFor(JsonNode.class);
30+
this(type, conv, mapper, null);
31+
2932
}
3033

3134
protected ReadPerfBaseFullJackson(Class<T> type, InputConverter conv,
@@ -45,6 +48,40 @@ protected ReadPerfBaseFullJackson(Class<T> type, InputConverter conv,
4548
r = r.with(schema);
4649
}
4750
NODE_READER = r;
51+
52+
// This is unlikely to actually work but:
53+
r = mapper.readerFor(Currency.class);
54+
if (schema != null) {
55+
r = r.with(schema);
56+
}
57+
CURRENCY_READER_DEFAULT = r;
58+
59+
r = mapper.readerFor(Currency.class)
60+
.with(StreamReadFeature.USE_FAST_DOUBLE_PARSER);
61+
if (schema != null) {
62+
r = r.with(schema);
63+
}
64+
CURRENCY_READER_FAST = r;
65+
}
66+
67+
/*
68+
/**********************************************************************
69+
/* Secondary POJO tests
70+
/**********************************************************************
71+
*/
72+
73+
@Benchmark
74+
@OutputTimeUnit(TimeUnit.SECONDS)
75+
@Override
76+
public void readCurrencyPojoDefault(Blackhole bh/*, AuxStateSize size*/) throws Exception {
77+
bh.consume(read(FULL_CONVERTER.bytes(InputData.CURRENCY_WS), CURRENCY_READER_DEFAULT));
78+
}
79+
80+
@Benchmark
81+
@OutputTimeUnit(TimeUnit.SECONDS)
82+
@Override
83+
public void readCurrencyPojoFast(Blackhole bh/*, AuxStateSize size*/) throws Exception {
84+
bh.consume(read(FULL_CONVERTER.bytes(InputData.CURRENCY_WS), CURRENCY_READER_FAST));
4885
}
4986

5087
/*

src/main/java/com/fasterxml/jackson/perf/ReadPerfTestFull.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ public interface ReadPerfTestFull extends ReadPerfTestBasic
1313
public void readNodeWebxml(Blackhole bh) throws Exception;
1414
public void readNodeMenu(Blackhole bh) throws Exception;
1515
public void readNodeMediaItem(Blackhole bh) throws Exception;
16+
17+
public void readCurrencyPojoDefault(Blackhole bh) throws Exception;
18+
public void readCurrencyPojoFast(Blackhole bh) throws Exception;
1619
}

src/main/java/com/fasterxml/jackson/perf/data/InputData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public enum InputData
1010
WEBXML_WS("json/webxml_ws.json"),
1111
MENU_WS("json/menu_ws.json"),
1212

13+
// Data for alternate POJOs or untyped
14+
CURRENCY_WS("json/USD.json")
1315
;
1416

1517
private final byte[] _json;

src/main/java/com/fasterxml/jackson/perf/json/JsonStringReadVanilla.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
import org.openjdk.jmh.annotations.Scope;
1010
import org.openjdk.jmh.infra.Blackhole;
1111

12+
import com.fasterxml.jackson.core.StreamReadFeature;
1213
import com.fasterxml.jackson.databind.*;
1314
import com.fasterxml.jackson.perf.*;
1415
import com.fasterxml.jackson.perf.data.InputData;
1516
import com.fasterxml.jackson.perf.data.StringInputConverter;
17+
import com.fasterxml.jackson.perf.model.Currency;
1618
import com.fasterxml.jackson.perf.model.MediaItem;
1719

1820
/**
@@ -34,7 +36,10 @@ public class JsonStringReadVanilla
3436
protected final ObjectReader UNTYPED_READER;
3537
protected final ObjectReader NODE_READER;
3638
protected final ObjectReader MEDIA_ITEM_READER;
37-
39+
40+
protected final ObjectReader CURRENCY_READER_DEFAULT;
41+
protected final ObjectReader CURRENCY_READER_FAST;
42+
3843
protected final StringInputConverter _converter;
3944

4045
public JsonStringReadVanilla() {
@@ -43,6 +48,10 @@ public JsonStringReadVanilla() {
4348
UNTYPED_READER = MAPPER.readerFor(Object.class);
4449
NODE_READER = MAPPER.readerFor(JsonNode.class);
4550
MEDIA_ITEM_READER = MAPPER.readerFor(MediaItem.class);
51+
CURRENCY_READER_DEFAULT = MAPPER.readerFor(Currency.class);
52+
CURRENCY_READER_FAST = CURRENCY_READER_DEFAULT
53+
.with(StreamReadFeature.USE_FAST_DOUBLE_PARSER);
54+
4655
}
4756

4857
protected Object read(String input, ObjectReader reader) throws IOException {
@@ -64,6 +73,24 @@ public void readPojoMediaItem(Blackhole bh/*, AuxStateSize size*/) throws Except
6473
bh.consume(read(input, MEDIA_ITEM_READER));
6574
}
6675

76+
@Benchmark
77+
@OutputTimeUnit(TimeUnit.SECONDS)
78+
@Override
79+
public void readCurrencyPojoDefault(Blackhole bh/*, AuxStateSize size*/) throws Exception {
80+
final String input = _converter.asString(InputData.CURRENCY_WS);
81+
// size.set(input.length());
82+
bh.consume(read(input, CURRENCY_READER_DEFAULT));
83+
}
84+
85+
@Benchmark
86+
@OutputTimeUnit(TimeUnit.SECONDS)
87+
@Override
88+
public void readCurrencyPojoFast(Blackhole bh/*, AuxStateSize size*/) throws Exception {
89+
final String input = _converter.asString(InputData.CURRENCY_WS);
90+
// size.set(input.length());
91+
bh.consume(read(input, CURRENCY_READER_FAST));
92+
}
93+
6794
/*
6895
/**********************************************************************
6996
/* Untyped ("map") reading tests
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fasterxml.jackson.perf.model;
2+
3+
import java.util.Map;
4+
5+
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
6+
7+
/**
8+
* Model class for data from
9+
* <a href="https://www.exchangerate-api.com">Exchange Rate</a>;
10+
* see {@code ./json/USD.json}.
11+
*
12+
*/
13+
@JsonIgnoreProperties({
14+
15+
})
16+
public class Currency {
17+
public String base, date, provider, terms;
18+
public int time_last_updated;
19+
20+
public Map<String, Double> rates;
21+
}

0 commit comments

Comments
 (0)