summaryrefslogtreecommitdiff
path: root/test/bench/go1
diff options
context:
space:
mode:
authorShenghou Ma <minux.ma@gmail.com>2012-06-05 00:14:39 +0800
committerShenghou Ma <minux.ma@gmail.com>2012-06-05 00:14:39 +0800
commite734c75f4b2ab1f683e2882a14c09a57b1869ee1 (patch)
treefb1c1a46b9538510cdf0f1b713647d3b9afe0e9e /test/bench/go1
parentd8bc89d67cddfe35cfe3d5b0eb3eb424c0917e8f (diff)
downloadgo-e734c75f4b2ab1f683e2882a14c09a57b1869ee1.tar.gz
test/bench/go1: fix gzip test
We can't depend on init() order, and certainly we don't want to register all future benchmarks that use jsonbytes or jsondata to init() in json_test.go, so we use a more general solution: make generation of jsonbytes and jsondata their own function so that the compiler will take care of the order. R=golang-dev, dave, rsc CC=golang-dev http://codereview.appspot.com/6282046
Diffstat (limited to 'test/bench/go1')
-rw-r--r--test/bench/go1/gob_test.go4
-rw-r--r--test/bench/go1/json_test.go15
2 files changed, 10 insertions, 9 deletions
diff --git a/test/bench/go1/gob_test.go b/test/bench/go1/gob_test.go
index 00eeed57a..b172b805a 100644
--- a/test/bench/go1/gob_test.go
+++ b/test/bench/go1/gob_test.go
@@ -21,9 +21,7 @@ var (
gobdata *JSONResponse
)
-func gobinit() {
- // gobinit is called after json's init,
- // because it uses jsondata.
+func init() {
gobdata = gobResponse(&jsondata)
var buf bytes.Buffer
diff --git a/test/bench/go1/json_test.go b/test/bench/go1/json_test.go
index 5a3012167..614e24a81 100644
--- a/test/bench/go1/json_test.go
+++ b/test/bench/go1/json_test.go
@@ -17,11 +17,11 @@ import (
)
var (
- jsonbytes []byte
- jsondata JSONResponse
+ jsonbytes = makeJsonBytes()
+ jsondata = makeJsonData()
)
-func init() {
+func makeJsonBytes() []byte {
var r io.Reader
r = strings.NewReader(jsonbz2_base64)
r = base64.NewDecoder(base64.StdEncoding, r)
@@ -30,12 +30,15 @@ func init() {
if err != nil {
panic(err)
}
- jsonbytes = b
+ return b
+}
- if err := json.Unmarshal(jsonbytes, &jsondata); err != nil {
+func makeJsonData() JSONResponse {
+ var v JSONResponse
+ if err := json.Unmarshal(jsonbytes, &v); err != nil {
panic(err)
}
- gobinit()
+ return v
}
type JSONResponse struct {