github.com/go-eden/common@v0.1.15-0.20210617133546-059099253264/emem/mem_asm_test.go (about) 1 package emem 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 "unsafe" 7 ) 8 9 func TestMemclr(t *testing.T) { 10 var data [12345]byte 11 12 for i := 0; i < len(data); i++ { 13 data[i] = byte(i) 14 } 15 memclr(unsafe.Pointer(&data), uintptr(len(data))) 16 17 assert.True(t, data[0] == 0) 18 assert.True(t, data[10] == 0) 19 assert.True(t, data[100] == 0) 20 assert.True(t, data[1000] == 0) 21 assert.True(t, data[len(data)-1] == 0) 22 } 23 24 func TestRound(t *testing.T) { 25 t.Log(roundupsize(1)) 26 t.Log(roundupsize(12)) 27 t.Log(roundupsize(123)) 28 t.Log(roundupsize(1234)) 29 t.Log(roundupsize(12345)) 30 t.Log(roundupsize(123456)) 31 } 32 33 // 34 // BenchmarkMemTool 35 // BenchmarkMemTool-12 32692742 36.6 ns/op 0 B/op 0 allocs/op 36 // BenchmarkMemTool2 37 // BenchmarkMemTool2-12 1000000 1039 ns/op 0 B/op 0 allocs/op 38 // BenchmarkMemTool3 39 // BenchmarkMemTool3-12 1000000 1032 ns/op 0 B/op 0 allocs/op 40 // 41 42 // BenchmarkMemTool-12 26022583 38.7 ns/op 0 B/op 0 allocs/op 43 func BenchmarkMemTool(b *testing.B) { 44 var blk [4096]byte 45 b.ReportAllocs() 46 b.ResetTimer() 47 for i := 0; i < b.N; i++ { 48 Clear(unsafe.Pointer(&blk), 4096) 49 } 50 } 51 52 // BenchmarkMemTool2-12 1104585 1045 ns/op 0 B/op 0 allocs/op 53 func BenchmarkMemTool2(b *testing.B) { 54 var blk [4096]byte 55 b.ReportAllocs() 56 b.ResetTimer() 57 for i := 0; i < b.N; i++ { 58 clearBlockForEach(&blk) 59 } 60 } 61 62 // BenchmarkMemTool2-12 1104585 1045 ns/op 0 B/op 0 allocs/op 63 func BenchmarkMemTool3(b *testing.B) { 64 var blk [4096]byte 65 b.ReportAllocs() 66 b.ResetTimer() 67 for i := 0; i < b.N; i++ { 68 for x := 0; x < len(blk); x++ { 69 blk[x] = 0 70 } 71 } 72 } 73 74 func clearBlockForEach(blk *[4096]byte) { 75 for x := 0; x < len(blk); x++ { 76 blk[x] = 0 77 } 78 }