Skip to content

Commit 7b48b0d

Browse files
committed
Update examples
1 parent fad97f8 commit 7b48b0d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

examples/advanced/zeromemorycopy/byteslice2string.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"unsafe"
1010

1111
"github.com/devlights/gomy/times"
12+
"github.com/devlights/gomy/zeromemcpy"
1213
)
1314

1415
// ByteSliceToString -- バイトスライスから文字列へメモリコピー無しに変換するサンプルです。
@@ -63,5 +64,13 @@ func ByteSliceToString() error {
6364
})
6465
fmt.Printf("[zeromemcpy] %v\n", elapsed)
6566

67+
// -------------------------------------
68+
// zeromemcpy.b2s
69+
// -------------------------------------
70+
elapsed = times.Stopwatch(func(start time.Time) {
71+
io.WriteString(io.Discard, zeromemcpy.B2S(b))
72+
})
73+
fmt.Printf("[zeromemcpy.B2S] %v\n", elapsed)
74+
6675
return nil
6776
}

examples/advanced/zeromemorycopy/string2byteslice.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"unsafe"
1111

1212
"github.com/devlights/gomy/times"
13+
"github.com/devlights/gomy/zeromemcpy"
1314
)
1415

1516
// StringToByteSlice -- 文字列からバイトスライスへメモリコピー無しに変換するサンプルです。
@@ -66,5 +67,13 @@ func StringToByteSlice() error {
6667
})
6768
fmt.Printf("[zeromemcpy] %v\n", elapsed)
6869

70+
// -------------------------------------
71+
// zeromemcpy.s2b
72+
// -------------------------------------
73+
elapsed = times.Stopwatch(func(start time.Time) {
74+
io.Discard.Write(zeromemcpy.S2B(s))
75+
})
76+
fmt.Printf("[zeromemcpy.s2b] %v\n", elapsed)
77+
6978
return nil
7079
}

0 commit comments

Comments
 (0)