commit
9111df2bd1
7 changed files with 249 additions and 0 deletions
@ -0,0 +1,12 @@ |
||||
#!/bin/bash |
||||
echo "=============== OFFICIAL GO ===============" > bench_run.txt |
||||
perf stat ./bench_go 1>>bench_run.txt 2>>bench_run.txt |
||||
echo "" >> bench_run.txt |
||||
|
||||
echo "=============== GCC GO ===============" >> bench_run.txt |
||||
perf stat ./bench_gccgo 1>>bench_run.txt 2>>bench_run.txt |
||||
echo "" >> bench_run.txt |
||||
|
||||
echo "=============== TINY GO ===============" >> bench_run.txt |
||||
perf stat ./bench_tinygo 1>>bench_run.txt 2>>bench_run.txt |
||||
echo "" >> bench_run.txt |
@ -0,0 +1,58 @@ |
||||
=============== OFFICIAL GO =============== |
||||
Performance counter stats for 'go build -o bench_go -a': |
||||
|
||||
5,564.00 msec task-clock:u # 3.548 CPUs utilized |
||||
0 context-switches:u # 0.000 K/sec |
||||
0 cpu-migrations:u # 0.000 K/sec |
||||
220,175 page-faults:u # 0.040 M/sec |
||||
19,917,018,145 cycles:u # 3.580 GHz |
||||
26,132,391,532 instructions:u # 1.31 insn per cycle |
||||
5,250,831,437 branches:u # 943.715 M/sec |
||||
136,368,966 branch-misses:u # 2.60% of all branches |
||||
|
||||
1.568412597 seconds time elapsed |
||||
|
||||
5.154106000 seconds user |
||||
0.457830000 seconds sys |
||||
|
||||
=============== GCC GO =============== |
||||
Performance counter stats for 'gccgo main.go -o bench_gccgo': |
||||
|
||||
152.41 msec task-clock:u # 0.895 CPUs utilized |
||||
0 context-switches:u # 0.000 K/sec |
||||
0 cpu-migrations:u # 0.000 K/sec |
||||
12,964 page-faults:u # 0.085 M/sec |
||||
389,073,532 cycles:u # 2.553 GHz |
||||
419,331,296 instructions:u # 1.08 insn per cycle |
||||
91,475,177 branches:u # 600.188 M/sec |
||||
3,496,910 branch-misses:u # 3.82% of all branches |
||||
|
||||
0.170248385 seconds time elapsed |
||||
|
||||
0.111306000 seconds user |
||||
0.042271000 seconds sys |
||||
|
||||
=============== TINY GO =============== |
||||
Performance counter stats for 'tinygo build -o bench_tinygo': |
||||
|
||||
102,160.05 msec task-clock:u # 1.010 CPUs utilized |
||||
0 context-switches:u # 0.000 K/sec |
||||
0 cpu-migrations:u # 0.000 K/sec |
||||
3,021,805 page-faults:u # 0.030 M/sec |
||||
318,444,441,214 cycles:u # 3.117 GHz |
||||
391,336,256,480 instructions:u # 1.23 insn per cycle |
||||
81,418,405,388 branches:u # 796.969 M/sec |
||||
640,957,898 branch-misses:u # 0.79% of all branches |
||||
|
||||
101.191178031 seconds time elapsed |
||||
|
||||
98.868438000 seconds user |
||||
3.654737000 seconds sys |
||||
|
||||
=============== BIN SIZE =============== |
||||
|
||||
| Name | Size | |
||||
|-------------------|---------| |
||||
| bench_go | 2.1M | |
||||
| bench_gccgo | 66K | |
||||
| bench_tinygo | 361K | |
Binary file not shown.
@ -0,0 +1,72 @@ |
||||
=============== OFFICIAL GO =============== |
||||
Nb prime found: 78498 IN 509.82006ms |
||||
Map final len: 2000000 IN 303.527414ms |
||||
Str final len: 516605 IN 4.221176024s |
||||
Total loop: 7445335968 IN 3.519736744s |
||||
|
||||
Performance counter stats for './bench_go': |
||||
|
||||
11,949.90 msec task-clock:u # 1.396 CPUs utilized |
||||
0 context-switches:u # 0.000 K/sec |
||||
0 cpu-migrations:u # 0.000 K/sec |
||||
31,341 page-faults:u # 0.003 M/sec |
||||
43,083,668,181 cycles:u # 3.605 GHz |
||||
64,460,591,523 instructions:u # 1.50 insn per cycle |
||||
12,784,649,567 branches:u # 1069.854 M/sec |
||||
70,885,922 branch-misses:u # 0.55% of all branches |
||||
|
||||
8.562514977 seconds time elapsed |
||||
|
||||
10.991747000 seconds user |
||||
1.724189000 seconds sys |
||||
|
||||
|
||||
|
||||
=============== GCC GO =============== |
||||
Nb prime found: 78498 IN 632.843018ms |
||||
Map final len: 2000000 IN 406.668759ms |
||||
Str final len: 516605 IN 2.944123142s |
||||
Total loop: 7445335968 IN 9.281379494s |
||||
|
||||
Performance counter stats for './bench_gccgo': |
||||
|
||||
14,097.62 msec task-clock:u # 1.058 CPUs utilized |
||||
0 context-switches:u # 0.000 K/sec |
||||
0 cpu-migrations:u # 0.000 K/sec |
||||
46,264 page-faults:u # 0.003 M/sec |
||||
59,189,356,897 cycles:u # 4.199 GHz |
||||
49,407,999,140 instructions:u # 0.83 insn per cycle |
||||
10,681,995,980 branches:u # 757.716 M/sec |
||||
22,769,581 branch-misses:u # 0.21% of all branches |
||||
|
||||
13.320942949 seconds time elapsed |
||||
|
||||
13.998379000 seconds user |
||||
0.234190000 seconds sys |
||||
|
||||
|
||||
|
||||
=============== TINY GO =============== |
||||
Nb prime found: 78498 IN 399.317119ms |
||||
Map final len: 2000000 IN 2h42m55.416901711s |
||||
Str final len: 516605 IN 3m29.684675044s |
||||
Total loop: 7445335968 IN 457.010533ms |
||||
|
||||
Performance counter stats for './bench_tinygo': |
||||
|
||||
9,985,515.96 msec task-clock:u # 1.000 CPUs utilized |
||||
0 context-switches:u # 0.000 K/sec |
||||
0 cpu-migrations:u # 0.000 K/sec |
||||
2,084,917 page-faults:u # 0.209 K/sec |
||||
28,273,670,043,780 cycles:u # 2.831 GHz |
||||
32,407,642,010,569 instructions:u # 1.15 insn per cycle |
||||
3,666,456,982,275 branches:u # 367.178 M/sec |
||||
8,102,030,527 branch-misses:u # 0.22% of all branches |
||||
|
||||
9986.216965017 seconds time elapsed |
||||
|
||||
9975.726034000 seconds user |
||||
2.937922000 seconds sys |
||||
|
||||
|
||||
|
Binary file not shown.
@ -0,0 +1,107 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"math" |
||||
"math/rand" |
||||
"time" |
||||
) |
||||
|
||||
type intime struct { |
||||
start time.Time |
||||
stop time.Time |
||||
duration time.Duration |
||||
} |
||||
|
||||
const itr int = 1000000 |
||||
|
||||
func (i *intime) Start() { |
||||
i.start = time.Now() |
||||
} |
||||
|
||||
func (i *intime) Stop() { |
||||
i.stop = time.Now() |
||||
i.duration = i.stop.Sub(i.start) |
||||
} |
||||
|
||||
func main() { |
||||
|
||||
rand.Seed(42) |
||||
|
||||
// Matth bench
|
||||
var matTime intime |
||||
matTime.Start() |
||||
|
||||
var nbPrime int |
||||
for i := range [itr]int{} { |
||||
if isPrime(i) { |
||||
nbPrime++ |
||||
} |
||||
} |
||||
|
||||
matTime.Stop() |
||||
fmt.Println("Nb prime found: ", nbPrime, "IN", matTime.duration) |
||||
|
||||
// Pointer bench
|
||||
var ptrTime intime |
||||
ptrTime.Start() |
||||
|
||||
mapb := make(map[int]int) |
||||
for range [itr * 2]int{} { |
||||
mapb[rand.Int()] = rand.Int() |
||||
} |
||||
|
||||
ptrTime.Stop() |
||||
fmt.Println("Map final len: ", len(mapb), "IN", ptrTime.duration) |
||||
|
||||
// String bench
|
||||
var strTime intime |
||||
strTime.Start() |
||||
|
||||
var str string |
||||
for range [itr / 16]int{} { |
||||
str = fmt.Sprintf("%s%q", str, rand.Intn(1000)) |
||||
str += fmt.Sprintf("%q", rand.Intn(1000)) |
||||
} |
||||
|
||||
strTime.Stop() |
||||
fmt.Println("Str final len: ", len(str), "IN", strTime.duration) |
||||
|
||||
// Loop bench
|
||||
var loopTime intime |
||||
loopTime.Start() |
||||
|
||||
var itrLoop int |
||||
for range [itr / 1024]int{} { |
||||
for range [itr / 512]int{} { |
||||
for range [itr / 256]int{} { |
||||
itrLoop++ |
||||
} |
||||
} |
||||
} |
||||
|
||||
loopTime.Stop() |
||||
fmt.Println("Total loop:", itrLoop, "IN", loopTime.duration) |
||||
} |
||||
|
||||
func isPrime(ic int) bool { |
||||
if ic <= 1 { |
||||
return false |
||||
} |
||||
|
||||
if ic < 2 { |
||||
return false |
||||
} |
||||
|
||||
if ic == 2 { |
||||
return true |
||||
} |
||||
|
||||
for i := 2; i < int(math.Sqrt(float64(ic)))+1; i++ { |
||||
if ic%i == 0 { |
||||
return false |
||||
} |
||||
} |
||||
|
||||
return true |
||||
} |
Loading…
Reference in new issue