Last active
December 18, 2015 12:39
-
-
Save cheald/5784471 to your computer and use it in GitHub Desktop.
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
$ go test -test.bench Json -file twitter_test.go | |
testing: warning: no tests to run | |
PASS | |
BenchmarkJsonEncode 50000 53661 ns/op | |
ok _/var/www/repos/twitter_test 4.038s |
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
package twitter | |
import "encoding/json" | |
import "net/http" | |
import "io/ioutil" | |
import "testing" | |
type Mention struct { | |
Name string | |
Id_str string | |
Id uint64 | |
Indices []uint8 | |
Screen_name string | |
} | |
type Url struct { | |
Expanded_url string | |
Url string | |
Indices []uint8 | |
} | |
type EntityList struct { | |
Urls []Url | |
Hashtags []string | |
User_mentions []Mention | |
} | |
type User struct { | |
Profile_sidebar_border_color string | |
Name string | |
Profile_sidebar_fill_color string | |
Profile_background_tile bool | |
Profile_image_url string | |
Location string | |
Created_at string | |
Id_str string | |
Follow_request_sent bool | |
Profile_link_color string | |
Favourites_count uint32 | |
Url string | |
Contributors_enabled bool | |
Utc_offset int32 | |
Id uint64 | |
Profile_use_background_image bool | |
Listed_count uint32 | |
Protected bool | |
Lang string | |
Profile_text_color string | |
Followers_count uint32 | |
Time_zone string | |
Verified bool | |
Geo_enabled bool | |
Profile_background_color string | |
Notifications bool | |
Description string | |
Friends_count uint32 | |
Profile_background_image_url string | |
Statuses_count uint32 | |
Screen_name string | |
Following bool | |
Show_all_inline_media bool | |
} | |
type TwitterAccount struct { | |
Coordinates string | |
Created_at string | |
Favorited bool | |
Truncated bool | |
Id_str string | |
Entities EntityList | |
In_reply_to_user_id_str string | |
Text string | |
Contributors string | |
Id uint64 | |
Retweet_count uint32 | |
In_reply_to_status_id_str string | |
Geo string | |
Retweeted bool | |
In_reply_to_user_id uint64 | |
User User | |
In_reply_to_screen_name string | |
Source string | |
Place string | |
In_reply_to_status_id uint64 | |
} | |
func BenchmarkJsonEncode(b *testing.B) { | |
b.StopTimer() | |
var account TwitterAccount | |
resp, _ := http.Get("https://gist.github.com/gnip/764239/raw/6c6a2297f3e4e29a626f07db0c57b45af7d7e5d7/Twitter+%28json+format%29.js") | |
defer resp.Body.Close() | |
body, _ := ioutil.ReadAll(resp.Body) | |
json.Unmarshal(body, &account) | |
b.StartTimer() | |
for i := 0; i < b.N; i++ { | |
json.Marshal(account) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment