Created
February 10, 2016 10:06
-
-
Save srdo/1b74a9f232cc0d8c132c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.schneiderelectric.test2; | |
import com.fasterxml.jackson.annotation.JsonProperty; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import java.io.ByteArrayOutputStream; | |
import java.io.ObjectOutputStream; | |
import java.io.Serializable; | |
import java.nio.charset.StandardCharsets; | |
import java.time.Instant; | |
public class Test { | |
public static void main(String[] args) throws Exception { | |
long t0 = System.currentTimeMillis(); | |
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); | |
for (int i = 0; i < 5_000_000; i++) { | |
byteStream = new ByteArrayOutputStream(); | |
ObjectOutputStream out = new ObjectOutputStream(byteStream); | |
out.writeObject(new ExampleClass()); | |
byteStream.reset(); | |
//System.out.println("Java serialization: " + byteStream.toByteArray().length); | |
} | |
System.out.println(System.currentTimeMillis() - t0); | |
long t1 = System.currentTimeMillis(); | |
ObjectMapper mapper = new ObjectMapper(); | |
for (int i = 0; i < 5_000_000; i++) { | |
byte[] jsonBytes = mapper.writeValueAsString(new ExampleClass()).getBytes(StandardCharsets.UTF_8); | |
//System.out.println("Json serialization: " + jsonBytes.length); | |
} | |
System.out.println(System.currentTimeMillis() - t1); | |
} | |
public static class ExampleClass implements Serializable { | |
@JsonProperty("anInstant") | |
private Instant anInstant = Instant.now(); | |
@JsonProperty("aNumber") | |
private int aNumber = 12; | |
@JsonProperty("aString") | |
private String aString = "Hello world"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment