-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.go
36 lines (32 loc) · 1.05 KB
/
utils.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
// Copyright 2021 The excelize Authors. All rights reserved. Use of
// this source code is governed by a BSD-style license.
//
// This is a benchmark script for the Go language Spreadsheet (Excel / XLSX)
// library excelize: https://github.com/xuri/excelize
package main
import (
"fmt"
"math/rand"
"runtime"
"syscall"
"time"
)
func randStringBytes(n int) string {
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
b := make([]byte, n)
for i := range b {
b[i] = letterBytes[rand.Intn(52)]
}
return string(b)
}
func printBenchmarkInfo(fn string, startTime time.Time) {
var memStats runtime.MemStats
var rusage syscall.Rusage
var bToMb = func(b uint64) uint64 {
return b / 1024 / 1024
}
runtime.ReadMemStats(&memStats)
syscall.Getrusage(syscall.RUSAGE_SELF, &rusage)
fmt.Printf("Func: %s \tRSS = %v MB\tAlloc = %v MB\tTotalAlloc = %v MB\tSys = %v MB\tNumGC = %v \tCost = %s\n",
fn, bToMb(uint64(rusage.Maxrss)), bToMb(memStats.Alloc), bToMb(memStats.TotalAlloc), bToMb(memStats.Sys), memStats.NumGC, time.Since(startTime))
}