data.go 5.9 KB

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