-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (34 loc) · 800 Bytes
/
main.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/edsrzf/mmap-go"
)
func main() {
chunkSize := flag.Int("chunk-size", os.Getpagesize(), "Chunk size to use")
size := flag.Int("size", os.Getpagesize()*1024, "Amount of bytes to allocate")
flag.Parse()
inputFile, err := os.CreateTemp("", "")
if err != nil {
panic(err)
}
defer func() {
_ = inputFile.Close()
_ = os.Remove(inputFile.Name())
}()
if err := inputFile.Truncate(int64(*size)); err != nil {
panic(err)
}
b, err := mmap.MapRegion(inputFile, *size, mmap.RDWR, 0, 0)
if err != nil {
panic(err)
}
defer b.Unmap()
p := make([]byte, *chunkSize)
beforeFirstChunk := time.Now()
copy(p, b[*chunkSize:])
afterFirstChunk := time.Since(beforeFirstChunk)
fmt.Println(afterFirstChunk.Nanoseconds())
}