-
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathinternal_test.go
More file actions
34 lines (29 loc) · 664 Bytes
/
internal_test.go
File metadata and controls
34 lines (29 loc) · 664 Bytes
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
// Copyright 2024 Roxy Light
// SPDX-License-Identifier: ISC
package sqlite
import (
"testing"
"unsafe"
"modernc.org/libc"
"modernc.org/libc/sys/types"
)
func BenchmarkGoStringN(b *testing.B) {
tls := libc.NewTLS()
const want = "Hello, World!\n"
ptr, err := malloc(tls, types.Size_t(len(want)+1))
if err != nil {
b.Fatal(err)
}
defer libc.Xfree(tls, ptr)
for i := 0; i < len(want); i++ {
*(*byte)(unsafe.Pointer(ptr + uintptr(i))) = want[i]
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
got := goStringN(ptr, len(want))
if got != want {
b.Errorf("goStringN(%#x, %d) = %q; want %q", ptr, len(want), got, want)
}
}
}