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

View File

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