该帖已经被评为良好帖
|
|
---|---|
作者 | 正文 |
发表时间:2011-09-02
wenshao 写道 是我重新做测试的时候搞错了,我做的测试比较如下:
我新作的测试如下: Decode EishayDecode fastjson 3,236 YoungGC 17 FullGC 0 EishayDecode fastjson 1,520 YoungGC 12 FullGC 0 EishayDecode fastjson 1,537 YoungGC 26 FullGC 0 EishayDecode fastjson 1,530 YoungGC 35 FullGC 0 EishayDecode fastjson 1,535 YoungGC 22 FullGC 0 EishayDecode jsonconvert 2,174 YoungGC 18 FullGC 0 EishayDecode jsonconvert 2,026 YoungGC 37 FullGC 0 EishayDecode jsonconvert 1,996 YoungGC 13 FullGC 0 EishayDecode jsonconvert 2,014 YoungGC 20 FullGC 0 EishayDecode jsonconvert 2,000 YoungGC 14 FullGC 0 EishayDecode jackson 4,987 YoungGC 50 FullGC 0 EishayDecode jackson 4,474 YoungGC 73 FullGC 0 EishayDecode jackson 4,456 YoungGC 57 FullGC 0 EishayDecode jackson 4,469 YoungGC 42 FullGC 0 EishayDecode jackson 4,437 YoungGC 13 FullGC 0 从这个测试来看,decode的性能,jsonconvert-0.1.0的性能和fastjson相差30%左右,比jackson快一倍以上。 测试的案例在上一个帖子中,这是我做的测试,你重新测试一遍,看我的测试是否有问题。 jvm-serializers 有使用文档么, 没用过~ |
|
返回顶楼 | |
发表时间:2011-09-02
我已经把https://github.com/eishay/jvm-serializers/的测试剥离出来了。你可以自己直接测试。
测试代码在这里: http://code.alibabatech.com/svn/fastjson/trunk/fastjson/src/test/java/data/ 包含3个java bean:MediaContent、Media、Image三个类。 package data.media; import java.util.List; @SuppressWarnings("serial") public class MediaContent implements java.io.Serializable { public Media media; public List<Image> images; public MediaContent() {} public MediaContent (Media media, List<Image> images) { this.media = media; this.images = images; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MediaContent that = (MediaContent) o; if (images != null ? !images.equals(that.images) : that.images != null) return false; if (media != null ? !media.equals(that.media) : that.media != null) return false; return true; } @Override public int hashCode() { int result = media != null ? media.hashCode() : 0; result = 31 * result + (images != null ? images.hashCode() : 0); return result; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[MediaContent: "); sb.append("media=").append(media); sb.append(", images=").append(images); sb.append("]"); return sb.toString(); } public void setMedia(Media media) { this.media = media; } public void setImages(List<Image> images) { this.images = images; } public Media getMedia() { return media; } public List<Image> getImages() { return images; } } package data.media; import static data.ReprUtil.repr; import java.util.List; @SuppressWarnings("serial") public class Media implements java.io.Serializable { public enum Player { JAVA, FLASH } public String uri; public String title; // Can be unset. public int width; public int height; public String format; public long duration; public long size; public int bitrate; // Can be unset. // required by JSONiJ public boolean hasBitrate; public List<String> persons; public Player player; // msgpack requires this public String copyright; // Can be unset. public Media(){ } public Media(String uri, String title, int width, int height, String format, long duration, long size, int bitrate, boolean hasBitrate, List<String> persons, Player player, String copyright){ this.uri = uri; this.title = title; this.width = width; this.height = height; this.format = format; this.duration = duration; this.size = size; this.bitrate = bitrate; this.hasBitrate = hasBitrate; this.persons = persons; this.player = player; this.copyright = copyright; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Media media = (Media) o; if (bitrate != media.bitrate) return false; if (duration != media.duration) return false; if (hasBitrate != media.hasBitrate) return false; if (height != media.height) return false; if (size != media.size) return false; if (width != media.width) return false; if (copyright != null ? !copyright.equals(media.copyright) : media.copyright != null) return false; if (format != null ? !format.equals(media.format) : media.format != null) return false; if (persons != null ? !persons.equals(media.persons) : media.persons != null) return false; if (player != media.player) return false; if (title != null ? !title.equals(media.title) : media.title != null) return false; if (uri != null ? !uri.equals(media.uri) : media.uri != null) return false; return true; } @Override public int hashCode() { int result = uri != null ? uri.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); result = 31 * result + width; result = 31 * result + height; result = 31 * result + (format != null ? format.hashCode() : 0); result = 31 * result + (int) (duration ^ (duration >>> 32)); result = 31 * result + (int) (size ^ (size >>> 32)); result = 31 * result + bitrate; result = 31 * result + (hasBitrate ? 1 : 0); result = 31 * result + (persons != null ? persons.hashCode() : 0); result = 31 * result + (player != null ? player.hashCode() : 0); result = 31 * result + (copyright != null ? copyright.hashCode() : 0); return result; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[Media "); sb.append("uri=").append(repr(uri)); sb.append(", title=").append(repr(title)); sb.append(", width=").append(width); sb.append(", height=").append(height); sb.append(", format=").append(repr(format)); sb.append(", duration=").append(duration); sb.append(", size=").append(size); sb.append(", hasBitrate=").append(hasBitrate); sb.append(", bitrate=").append(String.valueOf(bitrate)); sb.append(", persons=").append(repr(persons)); sb.append(", player=").append(player); sb.append(", copyright=").append(copyright); sb.append("]"); return sb.toString(); } public String getUri() { return uri; } public void setUri(String uri) { this.uri = uri; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; } public long getDuration() { return duration; } public void setDuration(long duration) { this.duration = duration; } public long getSize() { return size; } public void setSize(long size) { this.size = size; } public int getBitrate() { return bitrate; } public void setBitrate(int bitrate) { this.bitrate = bitrate; } public List<String> getPersons() { return persons; } public void setPersons(List<String> persons) { this.persons = persons; } public Player getPlayer() { return player; } public void setPlayer(Player player) { this.player = player; } public String getCopyright() { return copyright; } public void setCopyright(String copyright) { this.copyright = copyright; } } package data.media; import static data.ReprUtil.repr; public class Image implements java.io.Serializable { private static final long serialVersionUID = 1L; public enum Size { SMALL, LARGE } public String uri; public String title; // Can be null public int width; public int height; public Size size; public Image(){ } public Image(String uri, String title, int width, int height, Size size){ this.height = height; this.title = title; this.uri = uri; this.width = width; this.size = size; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Image image = (Image) o; if (height != image.height) return false; if (width != image.width) return false; if (size != image.size) return false; if (title != null ? !title.equals(image.title) : image.title != null) return false; if (uri != null ? !uri.equals(image.uri) : image.uri != null) return false; return true; } @Override public int hashCode() { int result = uri != null ? uri.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); result = 31 * result + width; result = 31 * result + height; result = 31 * result + (size != null ? size.hashCode() : 0); return result; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[Image "); sb.append("uri=").append(repr(uri)); sb.append(", title=").append(repr(title)); sb.append(", width=").append(width); sb.append(", height=").append(height); sb.append(", size=").append(size); sb.append("]"); return sb.toString(); } public void setUri(String uri) { this.uri = uri; } public void setTitle(String title) { this.title = title; } public void setWidth(int width) { this.width = width; } public void setHeight(int height) { this.height = height; } public void setSize(Size size) { this.size = size; } public String getUri() { return uri; } public String getTitle() { return title; } public int getWidth() { return width; } public int getHeight() { return height; } public Size getSize() { return size; } } 构造对象的代码: MediaContent content = new MediaContent(); Media media = new Media(); media.uri = "http://javaone.com/keynote.mpg"; media.title = "Javaone Keynote"; media.width = 640; media.height = 480; media.format = "video/mpg4"; media.duration = 18000000; media.size = 58982400; media.bitrate = 262144; media.persons = Arrays.asList("Bill Gates", "Steve Jobs"); media.player = Player.JAVA; media.copyright = null; content.setMedia(media); List<Image> images = new ArrayList<Image>(); { Image image = new Image(); image.setUri("http://javaone.com/keynote_large.jpg"); image.setTitle("Javaone Keynote"); image.setWidth(1024); image.setHeight(768); image.setSize(Size.LARGE); images.add(image); } { Image image = new Image(); image.setUri("http://javaone.com/keynote_small.jpg"); image.setTitle("Javaone Keynote"); image.setWidth(320); image.setHeight(240); image.setSize(Size.SMALL); images.add(image); } content.setImages(images); 输出的JSON文本 {"images":[{"height":768,"size":"LARGE","title":"Javaone Keynote","uri":"http://javaone.com/keynote_large.jpg","width":1024},{"height":240,"size":"SMALL","title":"Javaone Keynote","uri":"http://javaone.com/keynote_small.jpg","width":320}],"media":{"bitrate":262144,"duration":18000000,"format":"video/mpg4","height":480,"persons":["Bill Gates","Steve Jobs"],"player":"JAVA","size":58982400,"title":"Javaone Keynote","uri":"http://javaone.com/keynote.mpg","width":640}} |
|
返回顶楼 | |
发表时间:2011-09-02
最后修改:2011-09-02
wenshao 写道 我已经把https://github.com/eishay/jvm-serializers/的测试剥离出来了。你可以自己直接测试。
测试代码在这里: http://code.alibabatech.com/svn/fastjson/trunk/fastjson/src/test/java/data/ 包含3个java bean:MediaContent、Media、Image三个类。 package data.media; import java.util.List; @SuppressWarnings("serial") public class MediaContent implements java.io.Serializable { public Media media; public List<Image> images; public MediaContent() {} public MediaContent (Media media, List<Image> images) { this.media = media; this.images = images; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MediaContent that = (MediaContent) o; if (images != null ? !images.equals(that.images) : that.images != null) return false; if (media != null ? !media.equals(that.media) : that.media != null) return false; return true; } @Override public int hashCode() { int result = media != null ? media.hashCode() : 0; result = 31 * result + (images != null ? images.hashCode() : 0); return result; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[MediaContent: "); sb.append("media=").append(media); sb.append(", images=").append(images); sb.append("]"); return sb.toString(); } public void setMedia(Media media) { this.media = media; } public void setImages(List<Image> images) { this.images = images; } public Media getMedia() { return media; } public List<Image> getImages() { return images; } } package data.media; import static data.ReprUtil.repr; import java.util.List; @SuppressWarnings("serial") public class Media implements java.io.Serializable { public enum Player { JAVA, FLASH } public String uri; public String title; // Can be unset. public int width; public int height; public String format; public long duration; public long size; public int bitrate; // Can be unset. // required by JSONiJ public boolean hasBitrate; public List<String> persons; public Player player; // msgpack requires this public String copyright; // Can be unset. public Media(){ } public Media(String uri, String title, int width, int height, String format, long duration, long size, int bitrate, boolean hasBitrate, List<String> persons, Player player, String copyright){ this.uri = uri; this.title = title; this.width = width; this.height = height; this.format = format; this.duration = duration; this.size = size; this.bitrate = bitrate; this.hasBitrate = hasBitrate; this.persons = persons; this.player = player; this.copyright = copyright; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Media media = (Media) o; if (bitrate != media.bitrate) return false; if (duration != media.duration) return false; if (hasBitrate != media.hasBitrate) return false; if (height != media.height) return false; if (size != media.size) return false; if (width != media.width) return false; if (copyright != null ? !copyright.equals(media.copyright) : media.copyright != null) return false; if (format != null ? !format.equals(media.format) : media.format != null) return false; if (persons != null ? !persons.equals(media.persons) : media.persons != null) return false; if (player != media.player) return false; if (title != null ? !title.equals(media.title) : media.title != null) return false; if (uri != null ? !uri.equals(media.uri) : media.uri != null) return false; return true; } @Override public int hashCode() { int result = uri != null ? uri.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); result = 31 * result + width; result = 31 * result + height; result = 31 * result + (format != null ? format.hashCode() : 0); result = 31 * result + (int) (duration ^ (duration >>> 32)); result = 31 * result + (int) (size ^ (size >>> 32)); result = 31 * result + bitrate; result = 31 * result + (hasBitrate ? 1 : 0); result = 31 * result + (persons != null ? persons.hashCode() : 0); result = 31 * result + (player != null ? player.hashCode() : 0); result = 31 * result + (copyright != null ? copyright.hashCode() : 0); return result; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[Media "); sb.append("uri=").append(repr(uri)); sb.append(", title=").append(repr(title)); sb.append(", width=").append(width); sb.append(", height=").append(height); sb.append(", format=").append(repr(format)); sb.append(", duration=").append(duration); sb.append(", size=").append(size); sb.append(", hasBitrate=").append(hasBitrate); sb.append(", bitrate=").append(String.valueOf(bitrate)); sb.append(", persons=").append(repr(persons)); sb.append(", player=").append(player); sb.append(", copyright=").append(copyright); sb.append("]"); return sb.toString(); } public String getUri() { return uri; } public void setUri(String uri) { this.uri = uri; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; } public long getDuration() { return duration; } public void setDuration(long duration) { this.duration = duration; } public long getSize() { return size; } public void setSize(long size) { this.size = size; } public int getBitrate() { return bitrate; } public void setBitrate(int bitrate) { this.bitrate = bitrate; } public List<String> getPersons() { return persons; } public void setPersons(List<String> persons) { this.persons = persons; } public Player getPlayer() { return player; } public void setPlayer(Player player) { this.player = player; } public String getCopyright() { return copyright; } public void setCopyright(String copyright) { this.copyright = copyright; } } package data.media; import static data.ReprUtil.repr; public class Image implements java.io.Serializable { private static final long serialVersionUID = 1L; public enum Size { SMALL, LARGE } public String uri; public String title; // Can be null public int width; public int height; public Size size; public Image(){ } public Image(String uri, String title, int width, int height, Size size){ this.height = height; this.title = title; this.uri = uri; this.width = width; this.size = size; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Image image = (Image) o; if (height != image.height) return false; if (width != image.width) return false; if (size != image.size) return false; if (title != null ? !title.equals(image.title) : image.title != null) return false; if (uri != null ? !uri.equals(image.uri) : image.uri != null) return false; return true; } @Override public int hashCode() { int result = uri != null ? uri.hashCode() : 0; result = 31 * result + (title != null ? title.hashCode() : 0); result = 31 * result + width; result = 31 * result + height; result = 31 * result + (size != null ? size.hashCode() : 0); return result; } public String toString() { StringBuilder sb = new StringBuilder(); sb.append("[Image "); sb.append("uri=").append(repr(uri)); sb.append(", title=").append(repr(title)); sb.append(", width=").append(width); sb.append(", height=").append(height); sb.append(", size=").append(size); sb.append("]"); return sb.toString(); } public void setUri(String uri) { this.uri = uri; } public void setTitle(String title) { this.title = title; } public void setWidth(int width) { this.width = width; } public void setHeight(int height) { this.height = height; } public void setSize(Size size) { this.size = size; } public String getUri() { return uri; } public String getTitle() { return title; } public int getWidth() { return width; } public int getHeight() { return height; } public Size getSize() { return size; } } 构造对象的代码: MediaContent content = new MediaContent(); Media media = new Media(); media.uri = "http://javaone.com/keynote.mpg"; media.title = "Javaone Keynote"; media.width = 640; media.height = 480; media.format = "video/mpg4"; media.duration = 18000000; media.size = 58982400; media.bitrate = 262144; media.persons = Arrays.asList("Bill Gates", "Steve Jobs"); media.player = Player.JAVA; media.copyright = null; content.setMedia(media); List<Image> images = new ArrayList<Image>(); { Image image = new Image(); image.setUri("http://javaone.com/keynote_large.jpg"); image.setTitle("Javaone Keynote"); image.setWidth(1024); image.setHeight(768); image.setSize(Size.LARGE); images.add(image); } { Image image = new Image(); image.setUri("http://javaone.com/keynote_small.jpg"); image.setTitle("Javaone Keynote"); image.setWidth(320); image.setHeight(240); image.setSize(Size.SMALL); images.add(image); } content.setImages(images); 输出的JSON文本 {"images":[{"height":768,"size":"LARGE","title":"Javaone Keynote","uri":"http://javaone.com/keynote_large.jpg","width":1024},{"height":240,"size":"SMALL","title":"Javaone Keynote","uri":"http://javaone.com/keynote_small.jpg","width":320}],"media":{"bitrate":262144,"duration":18000000,"format":"video/mpg4","height":480,"persons":["Bill Gates","Steve Jobs"],"player":"JAVA","size":58982400,"title":"Javaone Keynote","uri":"http://javaone.com/keynote.mpg","width":640}} 澳~ 你这个MediaContent对象我的附件测试代码里面有, 构建的对象是468个字符。com.tencent.tendon.convert.jsontest.github.MediaContent , 类里面有main方法, 执行的结果跟你的结果还是有点差别, 我在linux上执行的结果比fastjson快50% , 你的结果却是比我快30%, 不知道是不是环境问题~ |
|
返回顶楼 | |
发表时间:2011-09-02
我的测试环境:
java -version java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03-383-11A511) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-383, mixed mode) uname -a Darwin adminmatoMacBook-Pro.local 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11 PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64 JVM启动参数 -server 建议你使用maven组织工程,否则要做测试麻烦一些,我相信别人也会有同感。 |
|
返回顶楼 | |
发表时间:2011-09-02
wenshao 写道 我的测试环境:
java -version java version "1.6.0_26" Java(TM) SE Runtime Environment (build 1.6.0_26-b03-383-11A511) Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02-383, mixed mode) uname -a Darwin adminmatoMacBook-Pro.local 11.1.0 Darwin Kernel Version 11.1.0: Tue Jul 26 16:07:11 PDT 2011; root:xnu-1699.22.81~1/RELEASE_X86_64 x86_64 JVM启动参数 -server 建议你使用maven组织工程,否则要做测试麻烦一些,我相信别人也会有同感。 jvm在非windows环境下默认都是 -server模式运行, 加不加都一样。 我的也是1.6.0_26 不习惯把工程文件放到svn上。 不用maven好多年了, |
|
返回顶楼 | |
发表时间:2011-09-02
温少的fastjson挺好的,希望可以努力接受jsonconvert的挑战!
|
|
返回顶楼 | |
发表时间:2011-09-02
wenshao 写道 先给你一个良好贴
之前我测试过jsonconvert-0.1.0beta版本,性能还可以,比jackson稍微差一些。 我想重新测试一遍,发现jsonconvert-0.1.0跑不过测试了。报错信息如下: jsonconvert- com.tencent.tendon.convert.json.JsonException: a json object text must begin with '{' (position = 1) at com.tencent.tendon.convert.json.JsonDefaultReader.checkObject(Unknown Source) at com.tencent.tendon.convert.json.JsonDefaultToken.convertFrom(Unknown Source) at com.tencent.tendon.convert.json.JsonTokens$JsonSimpleArrayToken.convertFrom(Unknown Source) at com.tencent.tendon.convert.json.JsonTokens$JsonSimpleArrayToken.convertFrom(Unknown Source) at com.tencent.tendon.convert.json.JsonConvert.convertArrayFrom(Unknown Source) at com.tencent.tendon.convert.json.JsonConvert.convertArrayFrom(Unknown Source) at com.alibaba.json.test.codec.JsonConvertCodec.decodeObject(JsonConvertCodec.java:21) at com.alibaba.json.test.benchmark.decode.EishayDecode.execute(EishayDecode.java:24) 由于错误发生,测试无法继续,拿不到性能数据,这次没办法作比较。 你自己的测试程序比较片面,我建议你使用更综合场景做测试。 比如说https://github.com/eishay/jvm-serializers/提供的测试。不过那有点麻烦,我已经剥离了其中的测试代码。在这里: http://code.alibabatech.com/svn/fastjson/trunk/fastjson/src/test/java/data/media/ 是一个这样的JSON文本: {"images":[{"height":768,"size":"LARGE","title":"Javaone Keynote","uri":"http://javaone.com/keynote_large.jpg","width":1024},{"height":240,"size":"SMALL","title":"Javaone Keynote","uri":"http://javaone.com/keynote_small.jpg","width":320}],"media":{"bitrate":262144,"duration":18000000,"format":"video/mpg4","height":480,"persons":["Bill Gates","Steve Jobs"],"player":"JAVA","size":58982400,"title":"Javaone Keynote","uri":"http://javaone.com/keynote.mpg","width":640}} 构建测试的代码: MediaContent content = new MediaContent(); Media media = new Media(); media.uri = "http://javaone.com/keynote.mpg"; media.title = "Javaone Keynote"; media.width = 640; media.height = 480; media.format = "video/mpg4"; media.duration = 18000000; media.size = 58982400; media.bitrate = 262144; media.persons = Arrays.asList("Bill Gates", "Steve Jobs"); media.player = Player.JAVA; media.copyright = null; content.setMedia(media); List<Image> images = new ArrayList<Image>(); { Image image = new Image(); image.setUri("http://javaone.com/keynote_large.jpg"); image.setTitle("Javaone Keynote"); image.setWidth(1024); image.setHeight(768); image.setSize(Size.LARGE); images.add(image); } { Image image = new Image(); image.setUri("http://javaone.com/keynote_small.jpg"); image.setTitle("Javaone Keynote"); image.setWidth(320); image.setHeight(240); image.setSize(Size.SMALL); images.add(image); } content.setImages(images); 有竞争才有进步,希望你能够把jsonconvert做得够好!希望你使用maven仓库发布jar和sources.jar,那样测试更方便一些。 温少真现身了,支持温少 |
|
返回顶楼 | |
发表时间:2011-09-02
没有更进一步的分析么
|
|
返回顶楼 | |
发表时间:2011-09-03
这样很好啊. 有竞争才会推动技术的进步. 支持温少和nbzhang, 希望你们给我们带来越来越好的json库, 同时二位大老能否另外开篇讲述一下二者的设计, 及为什么会比别家的快. 谢谢!!
|
|
返回顶楼 | |
发表时间:2011-09-03
fastjson已经到1.13了,比较全面了,正式使用也基本没什么问题。
jsonconvert才刚出来,文档和功能可能都还不能满足。 在性能和功能方面,我肯定会优先考虑功能是否能满足我的需求,再考虑性能。 希望两个Json Parser会更好。 |
|
返回顶楼 | |