aboutsummaryrefslogtreecommitdiff
path: root/test/bench
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2013-03-11 17:17:25 -0700
committerRob Pike <r@golang.org>2013-03-11 17:17:25 -0700
commit05403fa8fbfe1c6e44e1b015a6e990af11c81dfd (patch)
tree14b1891a4e5dd6764718cf79fa5a0163e8b340ff /test/bench
parent79d06d7286eb5ec3089f19dbf8542803007cd4c7 (diff)
downloadgo-05403fa8fbfe1c6e44e1b015a6e990af11c81dfd.tar.gz
go-05403fa8fbfe1c6e44e1b015a6e990af11c81dfd.zip
go/test/bench/go1: add printf and time format tests
Also rename the go parser test to GoParse so it doesn't grab the globally useful Parse name. R=golang-dev, dave CC=golang-dev https://golang.org/cl/7732044
Diffstat (limited to 'test/bench')
-rw-r--r--test/bench/go1/fmt_test.go68
-rw-r--r--test/bench/go1/parser_test.go2
-rw-r--r--test/bench/go1/time_test.go25
3 files changed, 94 insertions, 1 deletions
diff --git a/test/bench/go1/fmt_test.go b/test/bench/go1/fmt_test.go
new file mode 100644
index 0000000000..d3c695669c
--- /dev/null
+++ b/test/bench/go1/fmt_test.go
@@ -0,0 +1,68 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package go1
+
+// benchmark based on fmt/fmt_test.go
+
+import (
+ "bytes"
+ "fmt"
+ "testing"
+)
+
+func BenchmarkFmtFprintfEmpty(b *testing.B) {
+ var buf bytes.Buffer
+ for i := 0; i < b.N; i++ {
+ fmt.Fprintf(&buf, "")
+ }
+}
+
+func BenchmarkFmtFprintfString(b *testing.B) {
+ var buf bytes.Buffer
+ for i := 0; i < b.N; i++ {
+ buf.Reset()
+ fmt.Fprintf(&buf, "%s", "hello")
+ }
+}
+
+func BenchmarkFmtFprintfInt(b *testing.B) {
+ var buf bytes.Buffer
+ for i := 0; i < b.N; i++ {
+ buf.Reset()
+ fmt.Fprintf(&buf, "%d", 5)
+ }
+}
+
+func BenchmarkFmtFprintfIntInt(b *testing.B) {
+ var buf bytes.Buffer
+ for i := 0; i < b.N; i++ {
+ buf.Reset()
+ fmt.Fprintf(&buf, "%d %d", 5, 6)
+ }
+}
+
+func BenchmarkFmtFprintfPrefixedInt(b *testing.B) {
+ var buf bytes.Buffer
+ for i := 0; i < b.N; i++ {
+ buf.Reset()
+ fmt.Fprintf(&buf, "This is some meaningless prefix text that needs to be scanned %d", 6)
+ }
+}
+
+func BenchmarkFmtFprintfFloat(b *testing.B) {
+ var buf bytes.Buffer
+ for i := 0; i < b.N; i++ {
+ buf.Reset()
+ fmt.Fprintf(&buf, "%g", 5.23184)
+ }
+}
+
+func BenchmarkFmtManyArgs(b *testing.B) {
+ var buf bytes.Buffer
+ for i := 0; i < b.N; i++ {
+ buf.Reset()
+ fmt.Fprintf(&buf, "%2d/%2d/%2d %d:%d:%d %s %s\n", 3, 4, 5, 11, 12, 13, "hello", "world")
+ }
+}
diff --git a/test/bench/go1/parser_test.go b/test/bench/go1/parser_test.go
index 26580b8872..7848cadd22 100644
--- a/test/bench/go1/parser_test.go
+++ b/test/bench/go1/parser_test.go
@@ -33,7 +33,7 @@ func makeParserBytes() []byte {
return b
}
-func BenchmarkParse(b *testing.B) {
+func BenchmarkGoParse(b *testing.B) {
b.SetBytes(int64(len(parserbytes)))
for i := 0; i < b.N; i++ {
if _, err := parser.ParseFile(token.NewFileSet(), "", parserbytes, parser.ParseComments); err != nil {
diff --git a/test/bench/go1/time_test.go b/test/bench/go1/time_test.go
new file mode 100644
index 0000000000..4687de31c1
--- /dev/null
+++ b/test/bench/go1/time_test.go
@@ -0,0 +1,25 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package go1
+
+// benchmark based on time/time_test.go
+
+import (
+ "testing"
+ "time"
+)
+
+func BenchmarkTimeParse(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ time.Parse(time.ANSIC, "Mon Jan 2 15:04:05 2006")
+ }
+}
+
+func BenchmarkTimeFormat(b *testing.B) {
+ t := time.Unix(1265346057, 0)
+ for i := 0; i < b.N; i++ {
+ t.Format("Mon Jan 2 15:04:05 2006")
+ }
+}