package main
import (
"fmt"
"sync"
"time"
)
type test struct {
p1, p2 int64 // 删除一个变量,计算速度会有两三倍的差异哦!!!
x int64
}
var wg sync.WaitGroup
func main() {
start := time.Now()
v1 := &test{}
v2 := &test{}
var num int64 = 100000
var i int64
wg.Add(2)
go func() {
for i = 0; i < num; i++ {
v1.x = i
}
wg.Done()
}()
go func() {
for i = 0; i < num; i++ {
v2.x = i
}
wg.Done()
}()
wg.Wait()
fmt.Println(time.Now().Sub(start).Microseconds())
}