Last active
December 19, 2015 11:09
-
-
Save nu7hatch/5945218 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
chris@abyss · 1.9.3 · /tmp/bench_list | |
$ time go run slice.go | |
real 0m0.858s | |
user 0m0.732s | |
sys 0m0.112s | |
chris@abyss · 1.9.3 · /tmp/bench_list | |
$ time go run list.go | |
real 0m1.556s | |
user 0m1.376s | |
sys 0m0.164s |
This file contains hidden or 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
package main | |
import "container/list" | |
type bin struct { | |
value float64 | |
count float64 | |
} | |
func main() { | |
l := list.New() | |
for i := 0; i <= 5000000; i++ { | |
l.PushFront(&bin{1,2}) | |
} | |
for e := l.Front(); e != nil; e = e.Next() { | |
_ = e.Value.(*bin) | |
} | |
} |
This file contains hidden or 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
package main | |
type bin struct { | |
value float64 | |
count float64 | |
} | |
type BinList []*bin | |
func (l *BinList) Append(b *bin) { | |
(*l) = append((*l), b) | |
} | |
func (l *BinList) Len() int { | |
return len(*l) | |
} | |
func (l *BinList) ValueOf(i int) *bin { | |
return (*l)[i] | |
} | |
func (l *BinList) Each(f func(*bin)) { | |
for _, b := range (*l) { | |
f(b) | |
} | |
} | |
func main() { | |
l := BinList(make([]*bin, 0)) | |
for i := 0; i <= 5000000; i++ { | |
l.Append(&bin{1,2}) | |
} | |
for i := 0; i < l.Len(); i++ { | |
_ = l.ValueOf(i) | |
} | |
// slightly slower that traditional iterating over list elements (100ms of | |
// difference only though). | |
//l.Each(func(b *bin) { | |
// _ = b | |
//}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment