cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 1 | import java.io.*; |
| 2 | |
| 3 | import org.codehaus.jackson.*; |
| 4 | import org.codehaus.jackson.io.IOContext; |
cowtowncoder | 3f1dee8 | 2009-02-19 20:11:55 +0000 | [diff] [blame] | 5 | import org.codehaus.jackson.map.*; |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 6 | import org.codehaus.jackson.smile.SmileFactory; |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 7 | import org.codehaus.jackson.util.BufferRecycler; |
| 8 | |
| 9 | // json.org's reference implementation |
| 10 | import org.json.*; |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 11 | // Jsontool implementation |
| 12 | import com.sdicons.json.parser.JSONParser; |
| 13 | // Noggit: |
| 14 | //import org.apache.noggit.JSONParser; |
| 15 | |
cowtowncoder | 87b2481 | 2010-07-01 07:00:21 +0000 | [diff] [blame] | 16 | @SuppressWarnings("unused") |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 17 | public final class TestJsonPerf |
| 18 | { |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 19 | private final int REPS; |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 20 | |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 21 | private final static int TEST_PER_GC = 15; |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 22 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 23 | final JsonFactory _jsonFactory; |
| 24 | |
| 25 | final ObjectMapper _mapper; |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 26 | |
cowtowncoder | 2ed3a19 | 2010-06-30 17:13:07 +0000 | [diff] [blame] | 27 | final ObjectMapper _smileMapper; |
| 28 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 29 | final SmileFactory _smileFactory; |
| 30 | |
| 31 | final byte[] _jsonData; |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 32 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 33 | final byte[] _smileData; |
| 34 | |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 35 | protected int mBatchSize; |
| 36 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 37 | public TestJsonPerf(File f) throws IOException |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 38 | { |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 39 | _jsonFactory = new JsonFactory(); |
| 40 | _mapper = new ObjectMapper(_jsonFactory); |
| 41 | _smileFactory = new SmileFactory(); |
cowtowncoder | 2ed3a19 | 2010-06-30 17:13:07 +0000 | [diff] [blame] | 42 | _smileMapper = new ObjectMapper(_smileFactory); |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 43 | _jsonData = readData(f); |
| 44 | _smileData = convertToSmile(_jsonData); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 45 | |
cowtowncoder | c8cf6ad | 2009-01-14 23:52:52 +0000 | [diff] [blame] | 46 | // Let's try to guestimate suitable size... to get to 50 megs parsed |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 47 | REPS = (int) ((double) (50 * 1000 * 1000) / (double) _jsonData.length); |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 48 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 49 | System.out.println("Read "+_jsonData.length+" bytes (smile: "+_smileData.length+") from '"+f+"'; will do "+REPS+" reps"); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 50 | System.out.println(); |
| 51 | } |
| 52 | |
| 53 | public void test() |
| 54 | throws Exception |
| 55 | { |
| 56 | int i = 0; |
| 57 | int sum = 0; |
| 58 | |
| 59 | while (true) { |
| 60 | try { Thread.sleep(100L); } catch (InterruptedException ie) { } |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 61 | // Use 9 to test all... |
cowtowncoder | cb0f322 | 2010-07-23 05:56:05 +0000 | [diff] [blame] | 62 | int round = (i++ % 2); |
cowtowncoder | cf85f3b | 2008-04-07 05:20:29 +0000 | [diff] [blame] | 63 | |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 64 | long curr = System.currentTimeMillis(); |
| 65 | String msg; |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 66 | boolean lf = (round == 0); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 67 | |
| 68 | switch (round) { |
cowtowncoder | dea5fad | 2009-02-18 06:34:49 +0000 | [diff] [blame] | 69 | |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 70 | case 0: |
cowtowncoder | 2ed3a19 | 2010-06-30 17:13:07 +0000 | [diff] [blame] | 71 | msg = "Smile/data-bind"; |
| 72 | sum += testJacksonDatabind(_smileMapper, _smileData, REPS); |
| 73 | break; |
| 74 | |
| 75 | case 1: |
| 76 | msg = "Jackson/data-bind"; |
| 77 | sum += testJacksonDatabind(_mapper, _jsonData, REPS); |
| 78 | break; |
| 79 | |
| 80 | /* |
| 81 | case 0: |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 82 | msg = "Jackson/smile, stream"; |
| 83 | sum += testJacksonStream(REPS, _smileFactory, _smileData, true); |
| 84 | break; |
cowtowncoder | 1f4cc72 | 2010-06-21 03:18:07 +0000 | [diff] [blame] | 85 | case 1: |
| 86 | msg = "Jackson, stream/byte"; |
| 87 | sum += testJacksonStream(REPS, _jsonFactory, _jsonData, true); |
| 88 | break; |
| 89 | case 2: |
| 90 | msg = "Jackson, stream/char"; |
| 91 | sum += testJacksonStream(REPS, _jsonFactory, _jsonData, false); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 92 | break; |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 93 | |
cowtowncoder | 1f4cc72 | 2010-06-21 03:18:07 +0000 | [diff] [blame] | 94 | case 3: |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 95 | msg = "Jackson, Java types"; |
cowtowncoder | 2ed3a19 | 2010-06-30 17:13:07 +0000 | [diff] [blame] | 96 | sum += testJacksonDatabind(_mapper, REPS); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 97 | break; |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 98 | |
cowtowncoder | 1f4cc72 | 2010-06-21 03:18:07 +0000 | [diff] [blame] | 99 | case 4: |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 100 | msg = "Jackson, JSON types"; |
| 101 | sum += testJacksonJsonTypes(_mapper, REPS); |
| 102 | break; |
cowtowncoder | 1f4cc72 | 2010-06-21 03:18:07 +0000 | [diff] [blame] | 103 | |
| 104 | case 5: |
| 105 | msg = "Noggit"; |
| 106 | sum += testNoggit(REPS); |
| 107 | break; |
| 108 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 109 | case 6: |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 110 | msg = "Json.org"; |
| 111 | sum += testJsonOrg(REPS); |
| 112 | break; |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 113 | case 7: |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 114 | msg = "Json-simple"; |
| 115 | sum += testJsonSimple(REPS); |
| 116 | break; |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 117 | case 8: |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 118 | msg = "JSONTools (berlios.de)"; |
| 119 | sum += testJsonTools(REPS); |
| 120 | break; |
cowtowncoder | 2ed3a19 | 2010-06-30 17:13:07 +0000 | [diff] [blame] | 121 | */ |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 122 | default: |
| 123 | throw new Error("Internal error"); |
| 124 | } |
| 125 | |
| 126 | curr = System.currentTimeMillis() - curr; |
| 127 | if (lf) { |
| 128 | System.out.println(); |
| 129 | } |
| 130 | System.out.println("Test '"+msg+"' -> "+curr+" msecs (" |
| 131 | +(sum & 0xFF)+")."); |
| 132 | |
| 133 | |
| 134 | if ((i % TEST_PER_GC) == 0) { |
| 135 | System.out.println("[GC]"); |
| 136 | try { Thread.sleep(100L); } catch (InterruptedException ie) { } |
| 137 | System.gc(); |
| 138 | try { Thread.sleep(100L); } catch (InterruptedException ie) { } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | private final byte[] readData(File f) |
| 144 | throws IOException |
| 145 | { |
| 146 | int len = (int) f.length(); |
| 147 | byte[] data = new byte[len]; |
| 148 | int offset = 0; |
| 149 | FileInputStream fis = new FileInputStream(f); |
| 150 | |
| 151 | while (len > 0) { |
| 152 | int count = fis.read(data, offset, len-offset); |
| 153 | offset += count; |
| 154 | len -= count; |
| 155 | } |
| 156 | |
| 157 | return data; |
| 158 | } |
| 159 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 160 | private byte[] convertToSmile(byte[] json) throws IOException |
| 161 | { |
| 162 | JsonParser jp = _jsonFactory.createJsonParser(json); |
| 163 | ByteArrayOutputStream out = new ByteArrayOutputStream(200); |
cowtowncoder | a4f5865 | 2010-06-28 04:42:07 +0000 | [diff] [blame] | 164 | System.out.println("Converting and verifying Smile data..."); |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 165 | JsonGenerator jg = _smileFactory.createJsonGenerator(out); |
| 166 | while (jp.nextToken() != null) { |
cowtowncoder | a4f5865 | 2010-06-28 04:42:07 +0000 | [diff] [blame] | 167 | jg.copyCurrentEvent(jp); |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 168 | } |
| 169 | jp.close(); |
| 170 | jg.close(); |
cowtowncoder | a4f5865 | 2010-06-28 04:42:07 +0000 | [diff] [blame] | 171 | byte[] smileBytes = out.toByteArray(); |
cowtowncoder | 12e9855 | 2010-07-25 03:38:27 +0000 | [diff] [blame] | 172 | System.out.println("Written as "+smileBytes.length+" Smile bytes from "+json.length+" JSON bytes; will verify correctness"); |
cowtowncoder | a4f5865 | 2010-06-28 04:42:07 +0000 | [diff] [blame] | 173 | |
| 174 | // One more thing: let's actually verify correctness! |
| 175 | JsonParser sp = _smileFactory.createJsonParser(new ByteArrayInputStream(smileBytes)); |
| 176 | jp = _jsonFactory.createJsonParser(json); |
| 177 | while (true) { |
| 178 | JsonToken t1 = jp.nextToken(); |
| 179 | JsonToken t2; |
| 180 | try { |
| 181 | t2 = sp.nextToken(); |
| 182 | } catch (IOException ioe) { |
| 183 | System.err.println("WARN: problem for token matching input token "+t1+" at "+jp.getCurrentLocation()); |
| 184 | throw ioe; |
| 185 | } |
| 186 | if (t1 != t2) { |
| 187 | throw new IllegalArgumentException("Error: tokens differ (json: "+t1+", smile "+t2+") at "+jp.getCurrentLocation()); |
| 188 | } |
| 189 | if (t1 == null) break; |
| 190 | if (t1.isScalarValue() || t1 == JsonToken.FIELD_NAME) { |
| 191 | String str1 = jp.getText(); |
| 192 | String str2 = jp.getText(); |
| 193 | if (str1 == null) { |
| 194 | throw new IllegalArgumentException("Error: token texts differ (json: null, smile '"+str2+"') at "+jp.getCurrentLocation()); |
| 195 | } else if (!str1.equals(str2)) { |
| 196 | throw new IllegalArgumentException("Error: token texts differ (json: '"+str1+"', smile '"+str2+"') at "+jp.getCurrentLocation()); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | System.out.println("Verified Smile data ("+smileBytes.length+"): same as JSON ("+json.length+")"); |
| 201 | return smileBytes; |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 202 | } |
| 203 | |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 204 | protected int testJsonOrg(int reps) |
| 205 | throws Exception |
| 206 | { |
| 207 | Object ob = null; |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 208 | // Json.org's code only accepts Strings: |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 209 | String input = new String(_jsonData, "UTF-8"); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 210 | for (int i = 0; i < reps; ++i) { |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 211 | JSONTokener tok = new JSONTokener(input); |
| 212 | ob = tok.nextValue(); |
| 213 | } |
| 214 | return ob.hashCode(); |
| 215 | } |
| 216 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 217 | private int testJsonTools(int reps) |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 218 | throws Exception |
| 219 | { |
| 220 | Object ob = null; |
| 221 | for (int i = 0; i < reps; ++i) { |
| 222 | // Json-tools accepts streams, yay! |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 223 | JSONParser jp = new JSONParser(new ByteArrayInputStream(_jsonData), "byte stream"); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 224 | /* Hmmmh. Will we get just one object for the whole thing? |
| 225 | * Or a stream? Seems like just one |
| 226 | */ |
| 227 | //while ((ob = jp.nextValue()) != null) { ; } |
| 228 | ob = jp.nextValue(); |
| 229 | } |
| 230 | return ob.hashCode(); |
| 231 | } |
| 232 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 233 | private int testJsonSimple(int reps) |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 234 | throws Exception |
| 235 | { |
| 236 | // Json.org's code only accepts Strings: |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 237 | String input = new String(_jsonData, "UTF-8"); |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 238 | Object ob = null; |
| 239 | for (int i = 0; i < reps; ++i) { |
| 240 | ob = org.json.simple.JSONValue.parse(input); |
| 241 | } |
| 242 | return ob.hashCode(); |
| 243 | } |
| 244 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 245 | private int testNoggit(int reps) |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 246 | throws Exception |
| 247 | { |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 248 | ByteArrayInputStream bin = new ByteArrayInputStream(_jsonData); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 249 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 250 | char[] cbuf = new char[_jsonData.length]; |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 251 | |
cowtowncoder | 62f8711 | 2008-11-26 21:04:19 +0000 | [diff] [blame] | 252 | IOContext ctxt = new IOContext(new BufferRecycler(), this, false); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 253 | int sum = 0; |
| 254 | |
| 255 | for (int i = 0; i < reps; ++i) { |
| 256 | /* This may be unfair advantage (allocating buffer of exact |
| 257 | * size)? But let's do that for now |
| 258 | */ |
| 259 | //char[] cbuf = new char[mData.length]; |
| 260 | //InputStreamReader r = new InputStreamReader(bin, "UTF-8"); |
| 261 | byte[] bbuf = ctxt.allocReadIOBuffer(); |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 262 | /* 13-Jan-2009, tatu: Note: Noggit doesn't use our turbo-charged |
| 263 | * UTF8 codec by default. But let's make it as fast as we |
| 264 | * possibly can... |
| 265 | */ |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 266 | UTF8Reader r = new UTF8Reader(ctxt, bin, bbuf, 0, 0); |
| 267 | |
| 268 | bin.reset(); |
| 269 | org.apache.noggit.JSONParser jp = new org.apache.noggit.JSONParser(r, cbuf); |
| 270 | int type; |
| 271 | while ((type = jp.nextEvent()) != org.apache.noggit.JSONParser.EOF) { |
| 272 | if (type == org.apache.noggit.JSONParser.STRING) { |
| 273 | sum += jp.getString().length(); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | return sum; |
| 278 | } |
| 279 | |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 280 | private int testJacksonStream(int reps, JsonFactory factory, byte[] data, boolean fast) |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 281 | throws Exception |
| 282 | { |
| 283 | int sum = 0; |
| 284 | for (int i = 0; i < reps; ++i) { |
cowtowncoder | 4182936 | 2008-08-06 03:49:14 +0000 | [diff] [blame] | 285 | // note: fast is not used any more |
cowtowncoder | c8cf6ad | 2009-01-14 23:52:52 +0000 | [diff] [blame] | 286 | JsonParser jp; |
| 287 | |
| 288 | if (fast) { |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 289 | jp = factory.createJsonParser(data, 0, data.length); |
cowtowncoder | c8cf6ad | 2009-01-14 23:52:52 +0000 | [diff] [blame] | 290 | } else { |
cowtowncoder | 2f4d63b | 2010-06-20 04:07:16 +0000 | [diff] [blame] | 291 | jp = factory.createJsonParser(new ByteArrayInputStream(data)); |
cowtowncoder | c8cf6ad | 2009-01-14 23:52:52 +0000 | [diff] [blame] | 292 | } |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 293 | JsonToken t; |
| 294 | while ((t = jp.nextToken()) != null) { |
cowtowncoder | a4f5865 | 2010-06-28 04:42:07 +0000 | [diff] [blame] | 295 | /* |
| 296 | if (t == JsonToken.FIELD_NAME) System.err.println("'"+jp.getCurrentName()+"'"); |
| 297 | else System.err.println(""+t); |
| 298 | */ |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 299 | // Field names are always constructed |
cowtowncoder | cf85f3b | 2008-04-07 05:20:29 +0000 | [diff] [blame] | 300 | if (t == JsonToken.VALUE_STRING |
| 301 | //|| t == JsonToken.FIELD_NAME |
| 302 | ) { |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 303 | sum += jp.getText().length(); |
| 304 | } |
| 305 | } |
| 306 | jp.close(); |
| 307 | } |
| 308 | return sum; |
| 309 | } |
| 310 | |
cowtowncoder | 2ed3a19 | 2010-06-30 17:13:07 +0000 | [diff] [blame] | 311 | private int testJacksonDatabind(ObjectMapper mapper, byte[] data, int reps) |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 312 | throws Exception |
| 313 | { |
| 314 | Object ob = null; |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 315 | for (int i = 0; i < reps; ++i) { |
cowtowncoder | 6c77e7d | 2009-01-14 00:41:12 +0000 | [diff] [blame] | 316 | // This is "untyped"... Maps, Lists etc |
cowtowncoder | 2ed3a19 | 2010-06-30 17:13:07 +0000 | [diff] [blame] | 317 | ob = mapper.readValue(data, 0, data.length, Object.class); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 318 | } |
| 319 | return ob.hashCode(); // just to get some non-optimizable number |
| 320 | } |
| 321 | |
cowtowncoder | 2ed3a19 | 2010-06-30 17:13:07 +0000 | [diff] [blame] | 322 | private int testJacksonTree(ObjectMapper mapper, byte[] data, int reps) |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 323 | throws Exception |
| 324 | { |
| 325 | Object ob = null; |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 326 | for (int i = 0; i < reps; ++i) { |
cowtowncoder | 2ed3a19 | 2010-06-30 17:13:07 +0000 | [diff] [blame] | 327 | ob = mapper.readValue(data, 0, data.length, JsonNode.class); |
cowtowncoder | ba36461 | 2008-03-24 05:59:43 +0000 | [diff] [blame] | 328 | } |
| 329 | return ob.hashCode(); // just to get some non-optimizable number |
| 330 | } |
| 331 | |
| 332 | public static void main(String[] args) |
| 333 | throws Exception |
| 334 | { |
| 335 | if (args.length != 1) { |
| 336 | System.err.println("Usage: java ... <file>"); |
| 337 | System.exit(1); |
| 338 | } |
| 339 | new TestJsonPerf(new File(args[0])).test(); |
| 340 | } |
| 341 | } |
| 342 | |