init: v1.0.0
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type SimpleStruct struct {
|
||||
n int
|
||||
}
|
||||
|
||||
func BenchmarkStructureFalseSharing(b *testing.B) {
|
||||
structA := SimpleStruct{}
|
||||
structB := SimpleStruct{}
|
||||
wg := sync.WaitGroup{}
|
||||
M := 1000000
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
for j := 0; j < M; j++ {
|
||||
structA.n += j
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
go func() {
|
||||
for j := 0; j < M; j++ {
|
||||
structB.n += j
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
wg.Wait()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCopyAVX2(b *testing.B) {
|
||||
a := make([]byte, 128*1024*1024)
|
||||
c := make([]byte, 128*1024*1024)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
CopySlice_AVX2(a, c, len(c))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCopy(b *testing.B) {
|
||||
a := make([]byte, 128*1024*1024)
|
||||
c := make([]byte, 128*1024*1024)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
CopySlice(a, c, len(c))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
func CopySlice_AVX2(dst, src []byte, len int)
|
||||
func CopySlice(dst, src []byte, len int) {
|
||||
for i := 0; i < len; i++ {
|
||||
dst[i] = src[i]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "textflag.h"
|
||||
|
||||
// func CopySlice_AVX2(dst, src []byte, len int)
|
||||
TEXT ·CopySlice_AVX2(SB), NOSPLIT, $0
|
||||
MOVQ dst_data+0(FP), DI
|
||||
MOVQ src_data+24(FP), SI
|
||||
MOVQ len+32(FP), BX
|
||||
MOVQ $0, AX
|
||||
|
||||
LOOP:
|
||||
VMOVDQU 0(SI)(AX*1), Y0
|
||||
VMOVDQU Y0, 0(DI)(AX*1)
|
||||
ADDQ $32, AX
|
||||
CMPQ AX, BX
|
||||
JL LOOP
|
||||
RET
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// +build go1.10
|
||||
|
||||
package main
|
||||
|
||||
//void SayHello(_GoString_ s);
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
C.SayHello("Hello, World\n")
|
||||
}
|
||||
|
||||
//export SayHello
|
||||
func SayHello(s string) {
|
||||
fmt.Print(s)
|
||||
}
|
||||
Reference in New Issue
Block a user