This commit is contained in:
RedKale
2016-03-02 14:56:20 +08:00
parent be3237ca7d
commit e5092f9529
2 changed files with 40 additions and 18 deletions

View File

@@ -5,6 +5,7 @@
*/
package org.redkale.test.convert;
import java.util.*;
/**
@@ -45,24 +46,32 @@ public class ConvertRecord {
v.setMap(map);
return v;
}
/**
public static void main(String[] args) throws Exception {
final ConvertRecord entry = ConvertRecord.createDefault();
run(ConvertRecord.class, entry);
}
public static <T> void run(final Class<T> type, final T entry) throws Exception {
/**
final org.redkale.convert.json.JsonConvert convert = org.redkale.convert.json.JsonFactory.root().getConvert();
final String entryString = convert.convertTo(entry);
convert.convertFrom(type, entryString);
System.out.println("redkale-convert: " + convert.convertTo(entry));
com.alibaba.fastjson.JSON.parseObject(entryString, type);
System.out.println("fastjson 1.2.7: " + com.alibaba.fastjson.JSON.toJSONString(entry));
final com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
mapper.readValue(entryString, type);
System.out.println("jackson 2.7.2: " + mapper.writeValueAsString(entry));
final com.google.gson.Gson gson = new com.google.gson.Gson();
gson.fromJson(entryString, type);
System.out.println("google-gson 2.4: " + gson.toJson(entry));
System.out.println("google-gson 2.4: " + gson.toJson(entry));
System.out.println("------------------------------------------------");
System.out.println("组件 序列化耗时(ms) 反解析耗时(ms)");
System.out.println("组件 序列化耗时(ms) 反序列化耗时(ms)");
final int count = 10_0000;
long s = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
@@ -94,6 +103,20 @@ public class ConvertRecord {
System.out.println("\t " + e);
//----------------------------------------------------------------------------
s = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
mapper.writeValueAsString(entry);
}
e = System.currentTimeMillis() - s;
System.out.print("jackson 2.7.2 " + e);
s = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
mapper.readValue(entryString, type);
}
e = System.currentTimeMillis() - s;
System.out.println("\t " + e);
//----------------------------------------------------------------------------
s = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
gson.toJson(entry);
}
@@ -107,10 +130,9 @@ public class ConvertRecord {
e = System.currentTimeMillis() - s;
System.out.println("\t " + e);
//----------------------------------------------------------------------------
*/
}
*/
public String getAname() {
return aname;
}

View File

@@ -7,6 +7,7 @@ package org.redkale.test.convert.media;
import java.util.*;
import org.redkale.convert.json.*;
import org.redkale.test.convert.*;
/**
*
@@ -27,9 +28,8 @@ public class MediaContent implements java.io.Serializable {
}
public static void main(String[] args) throws Exception {
JsonConvert convert = JsonFactory.root().getConvert();
MediaContent content = MediaContent.createDefault();
System.out.println(content);
final MediaContent entry = MediaContent.createDefault();
ConvertRecord.run(MediaContent.class, entry);
}
public static MediaContent createDefault() {
@@ -37,12 +37,12 @@ public class MediaContent implements java.io.Serializable {
+ " media : {"
+ " uri : \"http://javaone.com/keynote.mpg\" ,"
+ " title : \"Javaone Keynote\" ,"
+ " width : 640 ,"
+ " height : 480 ,"
+ " width : -640 ,"
+ " height : -480 ,"
+ " format : \"video/mpg4\","
+ " duration : 18000000 ,"
+ " size : 58982400 ,"
+ " bitrate : 262144 ,"
+ " duration : -18000000 ,"
+ " size : -58982400 ,"
+ " bitrate : -262144 ,"
+ " persons : [\"Bill Gates\", \"Steve Jobs\"] ,"
+ " player : JAVA , "
+ " copyright : None"
@@ -50,14 +50,14 @@ public class MediaContent implements java.io.Serializable {
+ " {"
+ " uri : \"http://javaone.com/keynote_large.jpg\","
+ " title : \"Javaone Keynote\","
+ " width : 1024,"
+ " height : 768,"
+ " width : -1024,"
+ " height : -768,"
+ " size : LARGE"
+ " }, {"
+ " uri : \"http://javaone.com/keynote_small.jpg\", "
+ " title : \"Javaone Keynote\" , "
+ " width : 320 , "
+ " height : 240 , "
+ " width : -320 , "
+ " height : -240 , "
+ " size : SMALL"
+ " }"
+ " ]"