forked from alibaba/fastjson2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
469 additions
and
11 deletions.
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
benchmark/src/main/java/com/alibaba/fastjson2/benchmark/twitter/Twitter.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
package com.alibaba.fastjson2.benchmark.twitter; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.List; | ||
|
||
public class Twitter { | ||
public String text; | ||
public Boolean truncated; | ||
@JsonProperty("in_reply_to_user_id") | ||
public String inReplyToUserId; | ||
@JsonProperty("in_reply_to_status_id") | ||
public String inReplyToStatusId; | ||
public Boolean favorited; | ||
public String source; | ||
@JsonProperty("in_reply_to_screen_name") | ||
public String inReplyToScreenName; | ||
@JsonProperty("in_reply_to_status_id_str") | ||
public String inReplyToStatusIdStr; | ||
@JsonProperty("id_str") | ||
public String idStr; | ||
public Entities entities; | ||
public String contributors; | ||
public Boolean retweeted; | ||
@JsonProperty("in_reply_to_user_id_str") | ||
public String inReplyToUserIdStr; | ||
public String place; | ||
@JsonProperty("retweet_count") | ||
public Integer retweetCount; | ||
@JsonProperty("created_at") | ||
public String createdAt; | ||
|
||
@JsonProperty("retweeted_status") | ||
public RetweetedStatus retweetedStatus; | ||
public User user; | ||
public Long id; | ||
public String coordinates; | ||
public String geo; | ||
|
||
public static class UserMention { | ||
public List<Integer> indices; | ||
@JsonProperty("screen_name") | ||
public String screenName; | ||
@JsonProperty("id_str") | ||
public String idStr; | ||
public String name; | ||
public Integer id; | ||
} | ||
|
||
public static class Entities { | ||
@JsonProperty("user_mentions") | ||
public List<UserMention> userMentions; | ||
public List urls; | ||
public List hashtags; | ||
} | ||
|
||
public static class Hashtag { | ||
public String text; | ||
public List<Integer> indices; | ||
} | ||
|
||
public static class User { | ||
public String notifications; | ||
@JsonProperty("profile_use_background_image") | ||
public Boolean profileUseBackgroundImage; | ||
@JsonProperty("statuses_count") | ||
public Integer statusesCount; | ||
@JsonProperty("profile_background_color") | ||
public String profileBackgroundColor; | ||
@JsonProperty("followers_count") | ||
public Integer followersCount; | ||
@JsonProperty("profile_image_url") | ||
public String profileImageUrl; | ||
@JsonProperty("listed_count") | ||
public Integer listedCount; | ||
@JsonProperty("profile_background_image_url") | ||
public String profileBackgroundImageUrl; | ||
public String description; | ||
@JsonProperty("screen_name") | ||
public String screenName; | ||
@JsonProperty("default_profile") | ||
public Boolean defaultProfile; | ||
public Boolean verified; | ||
@JsonProperty("time_zone") | ||
public String timeZone; | ||
@JsonProperty("profile_text_color") | ||
public String profileTextColor; | ||
@JsonProperty("is_translator") | ||
public Boolean isTranslator; | ||
@JsonProperty("profile_sidebar_fill_color") | ||
public String profileSidebarFillColor; | ||
public String location; | ||
@JsonProperty("id_str") | ||
public String idStr; | ||
@JsonProperty("default_profile_image") | ||
public Boolean defaultProfileImage; | ||
@JsonProperty("profile_background_tile") | ||
public Boolean profileBackgroundTile; | ||
public String lang; | ||
@JsonProperty("friends_count") | ||
public Integer friendsCount; | ||
@JsonProperty("protected") | ||
public Boolean isProtected; | ||
@JsonProperty("favourites_count") | ||
public Integer favouritesCount; | ||
@JsonProperty("created_at") | ||
public String createdAt; | ||
@JsonProperty("profile_link_color") | ||
public String profileLinkColor; | ||
public String name; | ||
@JsonProperty("show_all_inline_media") | ||
public Boolean showAllInlineMedia; | ||
@JsonProperty("follow_request_sent") | ||
public String followRequestSent; | ||
@JsonProperty("geo_enabled") | ||
public Boolean geoEnabled; | ||
@JsonProperty("profile_sidebar_border_color") | ||
public String profileSidebarBorderColor; | ||
public String url; | ||
public Integer id; | ||
@JsonProperty("contributors_enabled") | ||
public Boolean contributorsEnabled; | ||
public String following; | ||
@JsonProperty("utc_offset") | ||
public String utcOffset; | ||
} | ||
|
||
public static class RetweetedStatus { | ||
public String text; | ||
public Boolean truncated; | ||
@JsonProperty("in_reply_to_user_id") | ||
public String inReplyToUserId; | ||
@JsonProperty("in_reply_to_status_id") | ||
public String inReplyToStatusId; | ||
public Boolean favorited; | ||
public String source; | ||
@JsonProperty("in_reply_to_screen_name") | ||
public String inReplyToScreenName; | ||
@JsonProperty("in_reply_to_status_id_str") | ||
public String inReplyToStatusIdStr; | ||
@JsonProperty("id_str") | ||
public String idStr; | ||
public Entities entities; | ||
public String contributors; | ||
public Boolean retweeted; | ||
@JsonProperty("in_reply_to_user_id_str") | ||
public String inReplyToUserIdStr; | ||
public String place; | ||
@JsonProperty("retweet_count") | ||
public Integer retweetCount; | ||
@JsonProperty("created_at") | ||
public String createdAt; | ||
public User user; | ||
public Long id; | ||
public String coordinates; | ||
public String geo; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
benchmark/src/main/java/com/alibaba/fastjson2/benchmark/twitter/TwitterParseString.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.alibaba.fastjson2.benchmark.twitter; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.gson.Gson; | ||
import org.apache.commons.io.IOUtils; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.Options; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.io.InputStream; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class TwitterParseString { | ||
static String str; | ||
static final ObjectMapper mapper = new ObjectMapper(); | ||
static final Gson gson = new Gson(); | ||
|
||
static { | ||
try { | ||
InputStream is = TwitterParseString.class.getClassLoader().getResourceAsStream("data/twitter.json"); | ||
str = IOUtils.toString(is, "UTF-8"); | ||
JSON.parseObject(str, Twitter.class); | ||
} catch (Throwable ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void fastjson2(Blackhole bh) { | ||
bh.consume(JSON.parseObject(str, Twitter.class)); | ||
} | ||
|
||
@Benchmark | ||
public void jackson(Blackhole bh) throws Exception { | ||
bh.consume(mapper.readValue(str, Twitter.class)); | ||
} | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
Options options = new OptionsBuilder() | ||
.include(TwitterParseString.class.getName()) | ||
.mode(Mode.Throughput) | ||
.timeUnit(TimeUnit.MILLISECONDS) | ||
.warmupIterations(3) | ||
.forks(1) | ||
.threads(16) | ||
.build(); | ||
new Runner(options).run(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
benchmark/src/test/java/com/alibaba/fastjson2/benchmark/twitter/TwitterParseStringTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.alibaba.fastjson2.benchmark.twitter; | ||
|
||
import static com.alibaba.fastjson2.benchmark.JMH.BH; | ||
|
||
public class TwitterParseStringTest { | ||
static final int LOOP = 1_000_000; | ||
static final TwitterParseString benchmark = new TwitterParseString(); | ||
|
||
public static void fastjson2() { | ||
for (int j = 0; j < 5; j++) { | ||
long start = System.currentTimeMillis(); | ||
for (int i = 0; i < LOOP; ++i) { | ||
benchmark.fastjson2(BH); | ||
} | ||
long millis = System.currentTimeMillis() - start; | ||
System.out.println("fastjson2 millis : " + millis); | ||
// zulu8.70.0.23 : 4128 | ||
// zulu11.64.19 : | ||
// zulu17.42.19 : | ||
} | ||
} | ||
|
||
public static void jackson() throws Exception { | ||
for (int j = 0; j < 5; j++) { | ||
long start = System.currentTimeMillis(); | ||
for (int i = 0; i < LOOP; ++i) { | ||
benchmark.jackson(BH); | ||
} | ||
long millis = System.currentTimeMillis() - start; | ||
System.out.println("jackson millis : " + millis); | ||
// zulu8.70.0.23 : 7605 | ||
// zulu11.52.13 : | ||
// zulu17.32.13 : | ||
} | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
// fastjson2(); | ||
jackson(); | ||
// fastjson1(); | ||
// gson(); | ||
// wastjson(); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.