-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_test.go
51 lines (44 loc) · 1.01 KB
/
print_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"os"
"testing"
)
var (
testData = []string{"a", "b", "c", "d", "e"}
)
func BenchmarkPrintln(b *testing.B) {
f, _ := os.OpenFile("first.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
defer f.Close()
for i :=0; i < b.N; i++ {
fmt.Fprintln(f, testData[0])
fmt.Fprintln(f, testData[1])
fmt.Fprintln(f, testData[2])
fmt.Fprintln(f, testData[3])
fmt.Fprintln(f, testData[4])
}
}
func BenchmarkConcat(b *testing.B) {
f, _ := os.OpenFile("second.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
defer f.Close()
for i := 0; i < b.N; i++ {
s := testData[0] + "\n"
s += testData[1] + "\n"
s += testData[2] + "\n"
s += testData[3] + "\n"
s += testData[4]
fmt.Fprintln(f, s)
}
}
func BenchmarkConcatOneLine(b *testing.B) {
f, _ := os.OpenFile("third.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
defer f.Close()
for i := 0; i < b.N; i++ {
s := testData[0] + "\n" +
testData[1] + "\n" +
testData[2] + "\n" +
testData[3] + "\n" +
testData[4]
fmt.Fprintln(f, s)
}
}