blob: 2613845488e489486fd50858f53a632894385520 [file] [log] [blame]
Tatu Saloranta3701caf2014-04-29 09:52:27 -07001package perf;
2
3import java.math.BigDecimal;
4import java.math.BigInteger;
5import java.util.*;
6
7import com.fasterxml.jackson.databind.ObjectMapper;
8import com.fasterxml.jackson.databind.ObjectWriter;
9
10/* Test modified from json-parsers-benchmark, to be able to profile
11 * Jackson implementation.
12 */
13public class ManualWritePerfWithAllTypes
Tatu Saloranta1daa2fb2014-04-29 23:46:16 -070014 extends ObjectWriterTestBase<ManualWritePerfWithAllTypes.AllTypes, ManualWritePerfWithAllTypes.AllTypes>
Tatu Saloranta3701caf2014-04-29 09:52:27 -070015{
16 @Override
17 protected int targetSizeMegs() { return 15; }
18
19 public static void main(String[] args) throws Exception
20 {
21 if (args.length != 0) {
22 System.err.println("Usage: java ...");
23 System.exit(1);
24 }
25 ObjectMapper m = new ObjectMapper();
26 AllTypes input1 = AllTypes.bigObject();
27 AllTypes input2 = AllTypes.bigObject();
28 new ManualWritePerfWithAllTypes().test(m,
29 "AllTypes/small-1", input1, AllTypes.class,
30 "AllTypes/small-2", input2, AllTypes.class);
31 }
32
33 @Override
Tatu Saloranta1daa2fb2014-04-29 23:46:16 -070034 protected double testSer(int REPS, Object value, ObjectWriter writer) throws Exception
Tatu Saloranta3701caf2014-04-29 09:52:27 -070035 {
36 final NopOutputStream out = new NopOutputStream();
37 long start = System.nanoTime();
38 byte[] output = null;
39
40 while (--REPS >= 0) {
41 output = writer.writeValueAsBytes(value);
42 }
43 hash = output.length;
44 long nanos = System.nanoTime() - start;
45 out.close();
Tatu Saloranta1daa2fb2014-04-29 23:46:16 -070046 return _msecsFromNanos(nanos);
Tatu Saloranta3701caf2014-04-29 09:52:27 -070047 }
48
49 // Value type for test
50 public static class AllTypes
51 {
52 enum FooEnum {
53 FOO, BAR;
54 }
55
56 protected String ignoreMe;
57
58 public String ignoreMe2;
59 public String ignoreMe3;
60
61 public int myInt;
62 public boolean myBoolean;
63 public short myShort;
64 public long myLong;
65 public String string;
66 public String string2;
67 public BigDecimal bigDecimal;
68 public BigInteger bigInteger;
69 public Date date;
70
71 public float myFloat;
72 public double myDouble;
73 public byte myByte;
74
75 public FooEnum foo;
76 public FooEnum bar;
77
78 public long someDate = new Date().getTime ();
79
80 public AllTypes allType;
81
82 public List<AllTypes> allTypes = new ArrayList<AllTypes>();
83
84 static AllTypes _small() {
85 AllTypes small = new AllTypes();
86 small.ignoreMe = "THIS WILL NOT PASS";
87 small.ignoreMe2 = "THIS WILL NOT PASS EITHER";
88 small.ignoreMe3 = "THIS WILL NOT PASS TOO";
89 small.bigDecimal = new BigDecimal("1.235678900");
90 small.date = new Date();
91 small.bar = FooEnum.BAR;
92 small.foo = FooEnum.FOO;
93 small.string = "Hi Mom";
94 small.myDouble = 1.2345d;
95 small.myFloat = 1.0f;
96 small.myShort = (short)1;
97 small.myByte = (byte)1;
98 return small;
99 }
100
101 public static AllTypes smallObject() {
102 AllTypes small = _small();
103 small.allType = _small();
104 small.allType.string = "Hi Dad";
105 small.allTypes = Arrays.asList(_small(), _small());
106 return small;
107 }
108
109 public static AllTypes bigObject() {
110 AllTypes big = new AllTypes();
111 final List<AllTypes> list = new ArrayList<AllTypes>();
112 for (int index = 0; index < 10000; index++) {
113 AllTypes item = new AllTypes();
114
115 item.ignoreMe = "THIS WILL NOT PASS";
116 item.ignoreMe2 = "THIS WILL NOT PASS EITHER";
117 item.ignoreMe3 = "THIS WILL NOT PASS TOO";
118 item.bigDecimal = new BigDecimal("1.235678900");
119 item.date = new Date ();
120 item.bar = FooEnum.BAR;
121 item.foo = FooEnum.FOO;
122 item.string = "Hi Mom" + System.currentTimeMillis();
123 item.myDouble = 1.2345d;
124 item.myFloat = 1.0f;
125 item.myShort = (short)1;
126 item.myByte = (byte)1;
127
128 list.add(item);
129 }
130 big.allTypes = list;
131 return big;
132 }
133 }
134}