Skip to content

Instantly share code, notes, and snippets.

@ussy
Created December 16, 2010 14:35
Show Gist options
  • Save ussy/743455 to your computer and use it in GitHub Desktop.
Save ussy/743455 to your computer and use it in GitHub Desktop.
Jackson
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import org.codehaus.jackson.map.ObjectMapper;
public class Main {
public static void main(String[] args) throws Exception {
Result result = createResult(1000);
// すぶり
long start = System.currentTimeMillis();
ObjectMapper mapper = new ObjectMapper();
mapper.getSerializationConfig().setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US));
mapper.writeValueAsString(result);
long end = System.currentTimeMillis();
System.out.println("Jackson:" + (end - start));
//
final int count = 100;
start = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
mapper.writeValueAsString(result);
}
end = System.currentTimeMillis();
System.out.println("Jackson:" + ((end - start) / count));
}
static Result createResult(long num) {
Result result = new Result();
for (long i = 0; i < num; i++) {
Person person = new Person();
person.id = i;
person.age = (int) (i % 100);
person.name = "たろう" + i;
person.birthday = new Date(System.currentTimeMillis() + i);
List<Person> children = new ArrayList<Person>();
for (int j = 0; j < 5; j++) {
Person child = new Person();
child.id = j;
child.age = (int) (i % 100);
child.name = "たろう" + i;
child.birthday = new Date(System.currentTimeMillis() + i);
children.add(child);
}
person.children = children;
result.persons.add(person);
}
return result;
}
static class Result {
public List<Person> persons = new ArrayList<Person>();
}
static class Person {
public long id;
public int age;
public String name;
public Date birthday;
public List<Person> children = new ArrayList<Person>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment