if goos != "android" && !t.iOS() {
// There are no tests in this directory, only benchmarks.
- // Check that the test binary builds but don't bother running it.
- // (It has init-time work to set up for the benchmarks that is not worth doing unnecessarily.)
- t.registerTest("bench_go1", "../test/bench/go1", t.goTest(), "-c", "-o="+os.DevNull)
+ // Check that the test binary builds.
+ t.registerTest("bench_go1", "../test/bench/go1", t.goTest(), ".")
}
if goos != "android" && !t.iOS() {
// Only start multiple test dir shards on builders,
// Not a benchmark; input for revcomp.
-var fastabytes = makefasta()
-
func makefasta() []byte {
var n int = 25e6
if runtime.GOARCH == "arm" || runtime.GOARCH == "mips" || runtime.GOARCH == "mips64" {
"testing"
)
-var (
- gobbytes []byte
- gobdata *JSONResponse
-)
-
-func init() {
- gobdata = gobResponse(&jsondata)
+func makeGob(jsondata *JSONResponse) (data *JSONResponse, b []byte) {
+ data = gobResponse(jsondata)
var buf bytes.Buffer
- if err := gob.NewEncoder(&buf).Encode(gobdata); err != nil {
+ if err := gob.NewEncoder(&buf).Encode(data); err != nil {
panic(err)
}
- gobbytes = buf.Bytes()
+ b = buf.Bytes()
var r JSONResponse
- if err := gob.NewDecoder(bytes.NewBuffer(gobbytes)).Decode(&r); err != nil {
+ if err := gob.NewDecoder(bytes.NewBuffer(b)).Decode(&r); err != nil {
panic(err)
}
- if !reflect.DeepEqual(gobdata, &r) {
+ if !reflect.DeepEqual(data, &r) {
log.Printf("%v\n%v", jsondata, r)
b, _ := json.Marshal(&jsondata)
br, _ := json.Marshal(&r)
log.Printf("%s\n%s\n", b, br)
panic("gob: encode+decode lost data")
}
+
+ return
}
// gob turns [] into null, so make a copy of the data structure like that
return n1
}
-func gobdec() {
- if gobbytes == nil {
- panic("gobdata not initialized")
- }
+func gobdec(b []byte) {
var r JSONResponse
- if err := gob.NewDecoder(bytes.NewBuffer(gobbytes)).Decode(&r); err != nil {
+ if err := gob.NewDecoder(bytes.NewBuffer(b)).Decode(&r); err != nil {
panic(err)
}
_ = r
}
-func gobenc() {
- if err := gob.NewEncoder(io.Discard).Encode(&gobdata); err != nil {
+func gobenc(data *JSONResponse) {
+ if err := gob.NewEncoder(io.Discard).Encode(data); err != nil {
panic(err)
}
}
func BenchmarkGobDecode(b *testing.B) {
- b.SetBytes(int64(len(gobbytes)))
+ jsonbytes := makeJsonBytes()
+ jsondata := makeJsonData(jsonbytes)
+ _, bytes := makeGob(jsondata)
+ b.ResetTimer()
+ b.SetBytes(int64(len(bytes)))
for i := 0; i < b.N; i++ {
- gobdec()
+ gobdec(bytes)
}
}
func BenchmarkGobEncode(b *testing.B) {
- b.SetBytes(int64(len(gobbytes)))
+ jsonbytes := makeJsonBytes()
+ jsondata := makeJsonData(jsonbytes)
+ data, bytes := makeGob(jsondata)
+ b.ResetTimer()
+ b.SetBytes(int64(len(bytes)))
for i := 0; i < b.N; i++ {
- gobenc()
+ gobenc(data)
}
}
"testing"
)
-var (
- jsongunz = bytes.Repeat(jsonbytes, 10)
- jsongz []byte
-)
+func makeGunzip(jsonbytes []byte) []byte {
+ return bytes.Repeat(jsonbytes, 10)
+}
-func init() {
+func makeGzip(jsongunz []byte) []byte {
var buf bytes.Buffer
c := gz.NewWriter(&buf)
c.Write(jsongunz)
c.Close()
- jsongz = buf.Bytes()
+ return buf.Bytes()
}
-func gzip() {
+func gzip(jsongunz []byte) {
c := gz.NewWriter(io.Discard)
if _, err := c.Write(jsongunz); err != nil {
panic(err)
}
}
-func gunzip() {
+func gunzip(jsongz []byte) {
r, err := gz.NewReader(bytes.NewBuffer(jsongz))
if err != nil {
panic(err)
}
func BenchmarkGzip(b *testing.B) {
+ jsonbytes := makeJsonBytes()
+ jsongunz := makeGunzip(jsonbytes)
+ b.ResetTimer()
b.SetBytes(int64(len(jsongunz)))
for i := 0; i < b.N; i++ {
- gzip()
+ gzip(jsongunz)
}
}
func BenchmarkGunzip(b *testing.B) {
+ jsonbytes := makeJsonBytes()
+ jsongunz := makeGunzip(jsonbytes)
+ jsongz := makeGzip(jsongunz)
+ b.ResetTimer()
b.SetBytes(int64(len(jsongunz)))
for i := 0; i < b.N; i++ {
- gunzip()
+ gunzip(jsongz)
}
}
"testing"
)
-var (
- jsonbytes = makeJsonBytes()
- jsondata = makeJsonData()
-)
-
func makeJsonBytes() []byte {
var r io.Reader
r = bytes.NewReader(bytes.Replace(jsonbz2_base64, []byte{'\n'}, nil, -1))
return b
}
-func makeJsonData() JSONResponse {
+func makeJsonData(jsonbytes []byte) *JSONResponse {
var v JSONResponse
if err := json.Unmarshal(jsonbytes, &v); err != nil {
panic(err)
}
- return v
+ return &v
}
type JSONResponse struct {
MeanT int64 `json:"mean_t"`
}
-func jsondec() {
+func jsondec(bytes []byte) {
var r JSONResponse
- if err := json.Unmarshal(jsonbytes, &r); err != nil {
+ if err := json.Unmarshal(bytes, &r); err != nil {
panic(err)
}
_ = r
}
-func jsonenc() {
- buf, err := json.Marshal(&jsondata)
+func jsonenc(data *JSONResponse) {
+ buf, err := json.Marshal(data)
if err != nil {
panic(err)
}
}
func BenchmarkJSONEncode(b *testing.B) {
+ jsonbytes := makeJsonBytes()
+ jsondata := makeJsonData(jsonbytes)
+ b.ResetTimer()
b.SetBytes(int64(len(jsonbytes)))
for i := 0; i < b.N; i++ {
- jsonenc()
+ jsonenc(jsondata)
}
}
func BenchmarkJSONDecode(b *testing.B) {
+ jsonbytes := makeJsonBytes()
+ b.ResetTimer()
b.SetBytes(int64(len(jsonbytes)))
for i := 0; i < b.N; i++ {
- jsondec()
+ jsondec(jsonbytes)
}
}
}
func BenchmarkRevcomp(b *testing.B) {
- b.SetBytes(int64(len(fastabytes)))
+ bytes := makefasta()
+ b.ResetTimer()
+ b.SetBytes(int64(len(bytes)))
for i := 0; i < b.N; i++ {
- revcomp(fastabytes)
+ revcomp(bytes)
}
}
return r
}
-var tmpl = template.Must(template.New("main").Parse(strings.Map(stripTabNL, tmplText)))
+func makeTemplate(jsonbytes []byte, jsondata *JSONResponse) *template.Template {
+ tmpl := template.Must(template.New("main").Parse(strings.Map(stripTabNL, tmplText)))
-func init() {
var buf bytes.Buffer
if err := tmpl.Execute(&buf, &jsondata); err != nil {
panic(err)
println(buf.Len(), len(jsonbytes))
panic("wrong output")
}
+ return tmpl
}
-func tmplexec() {
- if err := tmpl.Execute(io.Discard, &jsondata); err != nil {
+func tmplexec(tmpl *template.Template, jsondata *JSONResponse) {
+ if err := tmpl.Execute(io.Discard, jsondata); err != nil {
panic(err)
}
}
func BenchmarkTemplate(b *testing.B) {
+ jsonbytes := makeJsonBytes()
+ jsondata := makeJsonData(jsonbytes)
+ tmpl := makeTemplate(jsonbytes, jsondata)
+ b.ResetTimer()
b.SetBytes(int64(len(jsonbytes)))
for i := 0; i < b.N; i++ {
- tmplexec()
+ tmplexec(tmpl, jsondata)
}
}