-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: optimize listpack removeNext cost
- Loading branch information
1 parent
e9fcee0
commit 3ee9300
Showing
7 changed files
with
169 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"runtime" | ||
"runtime/debug" | ||
"time" | ||
|
||
"github.com/xgzlucario/rotom/internal/hash" | ||
) | ||
|
||
var previousPause time.Duration | ||
|
||
func gcPause() time.Duration { | ||
runtime.GC() | ||
var stats debug.GCStats | ||
debug.ReadGCStats(&stats) | ||
pause := stats.PauseTotal - previousPause | ||
previousPause = stats.PauseTotal | ||
return pause | ||
} | ||
|
||
func genKV(id int) (string, []byte) { | ||
k := fmt.Sprintf("%08x", id) | ||
return k, []byte(k) | ||
} | ||
|
||
func main() { | ||
c := "" | ||
flag.StringVar(&c, "obj", "map", "object to bench.") | ||
flag.Parse() | ||
fmt.Println(c) | ||
|
||
start := time.Now() | ||
|
||
switch c { | ||
case "map": | ||
m := map[int]any{} | ||
for i := 0; i < 10000; i++ { | ||
hm := hash.NewMap() | ||
for i := 0; i < 512; i++ { | ||
k, v := genKV(i) | ||
hm.Set(k, v) | ||
} | ||
m[i] = hm | ||
} | ||
|
||
case "zipmap": | ||
m := map[int]any{} | ||
for i := 0; i < 10000; i++ { | ||
hm := hash.NewZipMap() | ||
for i := 0; i < 512; i++ { | ||
k, v := genKV(i) | ||
hm.Set(k, v) | ||
} | ||
m[i] = hm | ||
} | ||
|
||
case "zipmap-compressed": | ||
m := map[int]any{} | ||
for i := 0; i < 10000; i++ { | ||
hm := hash.NewZipMap() | ||
for i := 0; i < 512; i++ { | ||
k, v := genKV(i) | ||
hm.Set(k, v) | ||
} | ||
hm.Compress() | ||
m[i] = hm | ||
} | ||
} | ||
cost := time.Since(start) | ||
|
||
var mem runtime.MemStats | ||
var stat debug.GCStats | ||
|
||
runtime.ReadMemStats(&mem) | ||
debug.ReadGCStats(&stat) | ||
|
||
fmt.Println("gcsys:", mem.GCSys/1024/1024, "mb") | ||
fmt.Println("heap inuse:", mem.HeapInuse/1024/1024, "mb") | ||
fmt.Println("heap object:", mem.HeapObjects/1024, "k") | ||
fmt.Println("gc:", stat.NumGC) | ||
fmt.Println("pause:", gcPause()) | ||
fmt.Println("cost:", cost) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters