-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperf.go
62 lines (44 loc) · 968 Bytes
/
perf.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
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"time"
)
/*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void show() {
}
*/
// #cgo LDFLAGS: -lstdc++
import "C"
//import "fmt"
func show() {
}
func main() {
now := time.Now()
for i := 0; i < 100000000; i = i + 1 {
C.show()
}
end_time := time.Now()
var dur_time time.Duration = end_time.Sub(now)
var elapsed_sec float64 = dur_time.Seconds()
fmt.Printf("cgo show function elapsed \nelapsed %f seconds\n",
elapsed_sec)
now = time.Now()
for i := 0; i < 100000000; i = i + 1 {
show()
}
end_time = time.Now()
dur_time = end_time.Sub(now)
elapsed_sec = dur_time.Seconds()
fmt.Printf("go show function elapsed \nelapsed %f seconds \n",
elapsed_sec)
var input string
fmt.Scanln(&input)
}
Output:
cgo show function elapsed
elapsed 6.610593 seconds
go show function elapsed
elapsed 0.033000 seconds