Debian Codegraph @

benchmark/data.go

raw
1 // Package benchmark provides a simple benchmark for easyjson against default serialization and ffjson.
2 // The data example is taken from https://dev.twitter.com/rest/reference/get/search/tweets
3 package benchmark
4
5 import (
6 "io/ioutil"
7 )
8
9 var largeStructText, _ = ioutil.ReadFile("example.json")
10 var xlStructData XLStruct
11
12 func init() {
13 for i := 0; i < 50; i++ {
14 xlStructData.Data = append(xlStructData.Data, largeStructData)
15 }
16 }
17
18 var smallStructText = []byte(`{"hashtags":[{"indices":[5, 10],"text":"some-text"}],"urls":[],"user_mentions":[]}`)
19 var smallStructData = Entities{
20 Hashtags: []Hashtag{{Indices: []int{5, 10}, Text: "some-text"}},
21 Urls: []*string{},
22 UserMentions: []*string{},
23 }
24
25 type SearchMetadata struct {
26 CompletedIn float64 `json:"completed_in"`
27 Count int `json:"count"`
28 MaxID int64 `json:"max_id"`
29 MaxIDStr string `json:"max_id_str"`
30 NextResults string `json:"next_results"`
31 Query string `json:"query"`
32 RefreshURL string `json:"refresh_url"`
33 SinceID int64 `json:"since_id"`
34 SinceIDStr string `json:"since_id_str"`
35 }
36
37 type Hashtag struct {
38 Indices []int `json:"indices"`
39 Text string `json:"text"`
40 }
41
42 //easyjson:json
43 type Entities struct {
44 Hashtags []Hashtag `json:"hashtags"`
45 Urls []*string `json:"urls"`
46 UserMentions []*string `json:"user_mentions"`
47 }
48
49 type UserEntityDescription struct {
50 Urls []*string `json:"urls"`
51 }
52
53 type URL struct {
54 ExpandedURL *string `json:"expanded_url"`
55 Indices []int `json:"indices"`
56 URL string `json:"url"`
57 }
58
59 type UserEntityURL struct {
60 Urls []URL `json:"urls"`
61 }
62
63 type UserEntities struct {
64 Description UserEntityDescription `json:"description"`
65 URL UserEntityURL `json:"url"`
66 }
67
68 type User struct {
69 ContributorsEnabled bool `json:"contributors_enabled"`
70 CreatedAt string `json:"created_at"`
71 DefaultProfile bool `json:"default_profile"`
72 DefaultProfileImage bool `json:"default_profile_image"`
73 Description string `json:"description"`
74 Entities UserEntities `json:"entities"`
75 FavouritesCount int `json:"favourites_count"`
76 FollowRequestSent *string `json:"follow_request_sent"`
77 FollowersCount int `json:"followers_count"`
78 Following *string `json:"following"`
79 FriendsCount int `json:"friends_count"`
80 GeoEnabled bool `json:"geo_enabled"`
81 ID int `json:"id"`
82 IDStr string `json:"id_str"`
83 IsTranslator bool `json:"is_translator"`
84 Lang string `json:"lang"`
85 ListedCount int `json:"listed_count"`
86 Location string `json:"location"`
87 Name string `json:"name"`
88 Notifications *string `json:"notifications"`
89 ProfileBackgroundColor string `json:"profile_background_color"`
90 ProfileBackgroundImageURL string `json:"profile_background_image_url"`
91 ProfileBackgroundImageURLHTTPS string `json:"profile_background_image_url_https"`
92 ProfileBackgroundTile bool `json:"profile_background_tile"`
93 ProfileImageURL string `json:"profile_image_url"`
94 ProfileImageURLHTTPS string `json:"profile_image_url_https"`
95 ProfileLinkColor string `json:"profile_link_color"`
96 ProfileSidebarBorderColor string `json:"profile_sidebar_border_color"`
97 ProfileSidebarFillColor string `json:"profile_sidebar_fill_color"`
98 ProfileTextColor string `json:"profile_text_color"`
99 ProfileUseBackgroundImage bool `json:"profile_use_background_image"`
100 Protected bool `json:"protected"`
101 ScreenName string `json:"screen_name"`
102 ShowAllInlineMedia bool `json:"show_all_inline_media"`
103 StatusesCount int `json:"statuses_count"`
104 TimeZone string `json:"time_zone"`
105 URL *string `json:"url"`
106 UtcOffset int `json:"utc_offset"`
107 Verified bool `json:"verified"`
108 }
109
110 type StatusMetadata struct {
111 IsoLanguageCode string `json:"iso_language_code"`
112 ResultType string `json:"result_type"`
113 }
114
115 type Status struct {
116 Contributors *string `json:"contributors"`
117 Coordinates *string `json:"coordinates"`
118 CreatedAt string `json:"created_at"`
119 Entities Entities `json:"entities"`
120 Favorited bool `json:"favorited"`
121 Geo *string `json:"geo"`
122 ID int64 `json:"id"`
123 IDStr string `json:"id_str"`
124 InReplyToScreenName *string `json:"in_reply_to_screen_name"`
125 InReplyToStatusID *string `json:"in_reply_to_status_id"`
126 InReplyToStatusIDStr *string `json:"in_reply_to_status_id_str"`
127 InReplyToUserID *string `json:"in_reply_to_user_id"`
128 InReplyToUserIDStr *string `json:"in_reply_to_user_id_str"`
129 Metadata StatusMetadata `json:"metadata"`
130 Place *string `json:"place"`
131 RetweetCount int `json:"retweet_count"`
132 Retweeted bool `json:"retweeted"`
133 Source string `json:"source"`
134 Text string `json:"text"`
135 Truncated bool `json:"truncated"`
136 User User `json:"user"`
137 }
138
139 //easyjson:json
140 type LargeStruct struct {
141 SearchMetadata SearchMetadata `json:"search_metadata"`
142 Statuses []Status `json:"statuses"`
143 }
144
145 //easyjson:json
146 type XLStruct struct {
147 Data []LargeStruct
148 }