Skip to content

Commit

Permalink
Add performance comparison between orderedmap and go built-in map (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
xcshuan authored and elliotchance committed Nov 17, 2019
1 parent c843b30 commit 9746d59
Show file tree
Hide file tree
Showing 2 changed files with 530 additions and 3 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,49 @@ beyond the first or last item.

If the map is changing while the iteration is in-flight it may produce
unexpected behavior.

## Performance

CPU: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz

RAM: 8GB

System: Windows 10

```shell
$go test -benchmem -run=^$ github.com/elliotchance/orderedmap -bench BenchmarkAll
```

map[int]bool

| | map | orderedmap |
| ------- | ------------------- | ------------------- |
| set | 198 ns/op, 44 B/op | 722 ns/op, 211 B/op |
| get | 18 ns/op, 0 B/op | 37.3 ns/op, 0 B/op |
| delete | 888 ns/op, 211 B/op | 280 ns/op, 44 B/op |
| Iterate | 206 ns/op, 44 B/op | 693 ns/op, 259 B/op |

map[string]bool(PS : Use strconv.Iota())

| | map | orderedmap |
| ----------- | ------------------- | ----------------------- |
| set | 421 ns/op, 86 B/op | 1048 ns/op, 243 B/op |
| get | 81.1 ns/op, 2 B/op | 97.8 ns/op, 2 B/op |
| delete | 737 ns/op, 122 B/op | 1188 ns/op, 251 B/op |
| Iterate all | 14706 ns/op, 1 B/op | 52671 ns/op, 16391 B/op |

Big map[int]bool (10000000 keys)

| | map | orderedmap |
| ----------- | -------------------------------- | ------------------------------- |
| set all | 1.834559 s/op, 423.9470291 MB/op | 7.5564667 s/op, 1784.1483 MB/op |
| get all | 2.6367878 s/op, 423.9698 MB/op | 9.0232475 s/op, 1784.1086 MB/op |
| Iterate all | 1.9526784 s/op, 423.9042 MB/op | 8.2495265 s/op, 1936.7619 MB/op |

Big map[string]bool (10000000 keys)

| | map | orderedmap |
| ----------- | --------------------------------- | ----------------------------------- |
| set all | 4.8893923 s/op, 921.33435 MB/op | 10.4405527 s/op, 2089.0144 MB/op |
| get all | 7.122791 s/op, 997.3802643 MB/op | 13.2613692 s/op, 2165.09521 MB/op |
| Iterate all | 5.1688922 s/op, 921.4619293 MB/op | 12.6623711 s/op, 2241.5272064 MB/op |
Loading

0 comments on commit 9746d59

Please sign in to comment.