Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Commit

Permalink
made some optimizations and updated benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
schigh committed Sep 5, 2018
1 parent 091f5cd commit 216dc3c
Show file tree
Hide file tree
Showing 29 changed files with 753 additions and 753 deletions.
16 changes: 8 additions & 8 deletions base/tmpl/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (slice {{.PackageType}}) Filter(f func({{.BaseType}}) bool) {{.PackageType}
// This function will iterate over the slice completely. No
// items in the slice should be mutated by this operation.
func (slice {{.PackageType}}) Each(f func({{.BaseType}})) {
for _, v := range slice {
f(v)
for i := 0; i < len(slice); i++ {
f(slice[i])
}
}

Expand All @@ -105,8 +105,8 @@ func (slice {{.PackageType}}) Each(f func({{.BaseType}})) {
// supplied function, and nil otherwise.
// No items in the slice should be mutated by this operation.
func (slice {{.PackageType}}) TryEach(f func({{.BaseType}}) error) (int, error) {
for i, v := range slice {
if err := f(v); err != nil {
for i := 0; i < len(slice); i++ {
if err := f(slice[i]); err != nil {
return i, err
}
}
Expand All @@ -121,8 +121,8 @@ func (slice {{.PackageType}}) TryEach(f func({{.BaseType}}) error) (int, error)
// cause the provided function to return true, and false otherwise.
// No items in the slice should be mutated by this operation.
func (slice {{.PackageType}}) IfEach(f func({{.BaseType}}) bool) (int, bool) {
for i, v := range slice {
if !f(v) {
for i := 0; i < len(slice); i++ {
if !f(slice[i]) {
return i, false
}
}
Expand All @@ -132,7 +132,7 @@ func (slice {{.PackageType}}) IfEach(f func({{.BaseType}}) bool) (int, bool) {

// Map will apply a function to each {{.BaseType}} in the slice and replace the previous value
func (slice {{.PackageType}}) Map(f func({{.BaseType}}) {{.BaseType}}) {
for i, v := range slice {
slice[i] = f(v)
for i := 0; i < len(slice); i++ {
slice[i] = f(slice[i])
}
}
2 changes: 1 addition & 1 deletion benchmarks/float32_slice.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PASS
ok github.com/schigh/slices 0.011s
ok github.com/schigh/slices 0.015s
2 changes: 1 addition & 1 deletion benchmarks/float64_slice.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PASS
ok github.com/schigh/slices 0.011s
ok github.com/schigh/slices 0.019s
82 changes: 41 additions & 41 deletions benchmarks/int16_slice.txt
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
goos: darwin
goarch: amd64
pkg: github.com/schigh/slices
BenchmarkInt16Slice_IndexOf/10_elements-8 200000000 8.65 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_IndexOf/100_elements-8 20000000 65.0 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_IndexOf/1000_elements-8 3000000 615 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_IndexOf/10000_elements-8 200000 5866 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_IndexOf/100000_elements-8 30000 43730 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Contains/10_elements-8 100000000 10.0 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Contains/100_elements-8 20000000 72.3 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Contains/1000_elements-8 2000000 619 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Contains/10000_elements-8 200000 5989 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Contains/100000_elements-8 30000 50590 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_SortAsc/10_elements-8 10000000 122 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortAsc/100_elements-8 3000000 531 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortAsc/1000_elements-8 300000 4384 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortAsc/10000_elements-8 30000 43677 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortAsc/100000_elements-8 3000 416181 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortDesc/10_elements-8 10000000 121 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortDesc/100_elements-8 3000000 561 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortDesc/1000_elements-8 300000 4504 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortDesc/10000_elements-8 30000 42551 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortDesc/100000_elements-8 3000 431944 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_Reverse/10_elements-8 200000000 8.57 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Reverse/100_elements-8 30000000 48.5 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Reverse/1000_elements-8 3000000 454 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Reverse/10000_elements-8 300000 4799 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Reverse/100000_elements-8 30000 48939 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Filter/10_elements-8 20000000 59.3 ns/op 32 B/op 1 allocs/op
BenchmarkInt16Slice_Filter/100_elements-8 5000000 382 ns/op 208 B/op 1 allocs/op
BenchmarkInt16Slice_Filter/1000_elements-8 300000 4231 ns/op 2048 B/op 1 allocs/op
BenchmarkInt16Slice_Filter/10000_elements-8 20000 85687 ns/op 20480 B/op 1 allocs/op
BenchmarkInt16Slice_Filter/100000_elements-8 2000 897005 ns/op 204800 B/op 1 allocs/op
BenchmarkInt16Slice_Each/10_elements-8 100000000 19.8 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Each/100_elements-8 10000000 184 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Each/1000_elements-8 1000000 1835 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Each/10000_elements-8 100000 17539 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Each/100000_elements-8 10000 178186 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Map/10_elements-8 50000000 24.0 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Map/100_elements-8 5000000 239 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Map/1000_elements-8 500000 2279 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Map/10000_elements-8 100000 22564 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Map/100000_elements-8 10000 229280 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_IndexOf/10_elements-8 200000000 6.18 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_IndexOf/100_elements-8 30000000 49.6 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_IndexOf/1000_elements-8 5000000 323 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_IndexOf/10000_elements-8 500000 3091 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_IndexOf/100000_elements-8 100000 13823 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Contains/10_elements-8 200000000 8.13 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Contains/100_elements-8 30000000 55.7 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Contains/1000_elements-8 5000000 334 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Contains/10000_elements-8 500000 3137 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Contains/100000_elements-8 1000000 1201 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_SortAsc/10_elements-8 10000000 128 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortAsc/100_elements-8 3000000 601 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortAsc/1000_elements-8 300000 4905 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortAsc/10000_elements-8 30000 46127 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortAsc/100000_elements-8 3000 450736 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortDesc/10_elements-8 10000000 127 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortDesc/100_elements-8 3000000 626 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortDesc/1000_elements-8 300000 4901 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortDesc/10000_elements-8 30000 56070 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_SortDesc/100000_elements-8 3000 636746 ns/op 64 B/op 2 allocs/op
BenchmarkInt16Slice_Reverse/10_elements-8 100000000 12.7 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Reverse/100_elements-8 30000000 71.4 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Reverse/1000_elements-8 3000000 592 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Reverse/10000_elements-8 200000 7759 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Reverse/100000_elements-8 30000 54777 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Filter/10_elements-8 20000000 59.7 ns/op 32 B/op 1 allocs/op
BenchmarkInt16Slice_Filter/100_elements-8 5000000 416 ns/op 208 B/op 1 allocs/op
BenchmarkInt16Slice_Filter/1000_elements-8 300000 5152 ns/op 2048 B/op 1 allocs/op
BenchmarkInt16Slice_Filter/10000_elements-8 20000 96074 ns/op 20480 B/op 1 allocs/op
BenchmarkInt16Slice_Filter/100000_elements-8 2000 1045650 ns/op 204800 B/op 1 allocs/op
BenchmarkInt16Slice_Each/10_elements-8 100000000 22.0 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Each/100_elements-8 10000000 231 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Each/1000_elements-8 1000000 2074 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Each/10000_elements-8 100000 23602 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Each/100000_elements-8 10000 218008 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Map/10_elements-8 50000000 26.3 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Map/100_elements-8 5000000 272 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Map/1000_elements-8 500000 2358 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Map/10000_elements-8 50000 23880 ns/op 0 B/op 0 allocs/op
BenchmarkInt16Slice_Map/100000_elements-8 5000 239089 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/schigh/slices 70.188s
ok github.com/schigh/slices 74.307s
82 changes: 41 additions & 41 deletions benchmarks/int32_slice.txt
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
goos: darwin
goarch: amd64
pkg: github.com/schigh/slices
BenchmarkInt32Slice_IndexOf/10_elements-8 200000000 6.02 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_IndexOf/100_elements-8 30000000 49.9 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_IndexOf/1000_elements-8 5000000 321 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_IndexOf/10000_elements-8 500000 3008 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_IndexOf/100000_elements-8 50000 30209 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Contains/10_elements-8 200000000 7.84 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Contains/100_elements-8 30000000 50.8 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Contains/1000_elements-8 5000000 309 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Contains/10000_elements-8 500000 3004 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Contains/100000_elements-8 50000 30149 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_SortAsc/10_elements-8 10000000 118 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortAsc/100_elements-8 3000000 525 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortAsc/1000_elements-8 300000 4244 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortAsc/10000_elements-8 30000 40273 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortAsc/100000_elements-8 3000 406501 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortDesc/10_elements-8 20000000 117 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortDesc/100_elements-8 3000000 521 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortDesc/1000_elements-8 300000 4294 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortDesc/10000_elements-8 30000 42643 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortDesc/100000_elements-8 3000 411397 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_Reverse/10_elements-8 200000000 8.61 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Reverse/100_elements-8 30000000 47.5 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Reverse/1000_elements-8 3000000 462 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Reverse/10000_elements-8 300000 4786 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Reverse/100000_elements-8 30000 51371 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Filter/10_elements-8 30000000 59.7 ns/op 48 B/op 1 allocs/op
BenchmarkInt32Slice_Filter/100_elements-8 3000000 445 ns/op 416 B/op 1 allocs/op
BenchmarkInt32Slice_Filter/1000_elements-8 300000 4353 ns/op 4096 B/op 1 allocs/op
BenchmarkInt32Slice_Filter/10000_elements-8 20000 89104 ns/op 40960 B/op 1 allocs/op
BenchmarkInt32Slice_Filter/100000_elements-8 2000 969870 ns/op 401408 B/op 1 allocs/op
BenchmarkInt32Slice_Each/10_elements-8 100000000 20.8 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Each/100_elements-8 10000000 193 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Each/1000_elements-8 1000000 1877 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Each/10000_elements-8 100000 18344 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Each/100000_elements-8 10000 188349 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Map/10_elements-8 50000000 24.6 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Map/100_elements-8 5000000 239 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Map/1000_elements-8 1000000 2329 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Map/10000_elements-8 100000 22549 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Map/100000_elements-8 10000 232370 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_IndexOf/10_elements-8 200000000 6.09 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_IndexOf/100_elements-8 30000000 50.8 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_IndexOf/1000_elements-8 5000000 332 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_IndexOf/10000_elements-8 500000 3298 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_IndexOf/100000_elements-8 50000 35760 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Contains/10_elements-8 200000000 8.66 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Contains/100_elements-8 30000000 55.5 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Contains/1000_elements-8 5000000 337 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Contains/10000_elements-8 500000 3285 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Contains/100000_elements-8 50000 31928 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_SortAsc/10_elements-8 10000000 129 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortAsc/100_elements-8 2000000 726 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortAsc/1000_elements-8 200000 6350 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortAsc/10000_elements-8 20000 56139 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortAsc/100000_elements-8 3000 493512 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortDesc/10_elements-8 10000000 152 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortDesc/100_elements-8 2000000 949 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortDesc/1000_elements-8 300000 5743 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortDesc/10000_elements-8 30000 49130 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_SortDesc/100000_elements-8 3000 485209 ns/op 64 B/op 2 allocs/op
BenchmarkInt32Slice_Reverse/10_elements-8 200000000 9.42 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Reverse/100_elements-8 30000000 51.5 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Reverse/1000_elements-8 3000000 484 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Reverse/10000_elements-8 300000 5298 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Reverse/100000_elements-8 30000 56416 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Filter/10_elements-8 20000000 61.2 ns/op 48 B/op 1 allocs/op
BenchmarkInt32Slice_Filter/100_elements-8 3000000 432 ns/op 416 B/op 1 allocs/op
BenchmarkInt32Slice_Filter/1000_elements-8 300000 5577 ns/op 4096 B/op 1 allocs/op
BenchmarkInt32Slice_Filter/10000_elements-8 20000 95655 ns/op 40960 B/op 1 allocs/op
BenchmarkInt32Slice_Filter/100000_elements-8 2000 1029504 ns/op 401408 B/op 1 allocs/op
BenchmarkInt32Slice_Each/10_elements-8 100000000 22.6 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Each/100_elements-8 5000000 243 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Each/1000_elements-8 1000000 2021 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Each/10000_elements-8 100000 18874 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Each/100000_elements-8 10000 219557 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Map/10_elements-8 50000000 24.9 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Map/100_elements-8 5000000 243 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Map/1000_elements-8 1000000 2618 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Map/10000_elements-8 50000 23905 ns/op 0 B/op 0 allocs/op
BenchmarkInt32Slice_Map/100000_elements-8 10000 239400 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/schigh/slices 73.460s
ok github.com/schigh/slices 76.832s
Loading

0 comments on commit 216dc3c

Please sign in to comment.