Last active
September 19, 2015 18:03
-
-
Save apg/dce88df81835816d5a53 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
[apg@amend soa]$ go test -bench=. | |
testing: warning: no tests to run | |
PASS | |
BenchmarkAOS10 20000000 77.2 ns/op | |
Benchmark1AOS10 20000000 78.1 ns/op | |
BenchmarkSOA10 20000000 65.2 ns/op | |
BenchmarkAOS100 2000000 748 ns/op | |
Benchmark1AOS100 2000000 749 ns/op | |
BenchmarkSOA100 2000000 649 ns/op | |
BenchmarkAOS1000 200000 6864 ns/op | |
Benchmark1AOS1000 200000 6779 ns/op | |
BenchmarkSOA1000 300000 5449 ns/op | |
BenchmarkAOS10000 20000 70138 ns/op | |
Benchmark1AOS10000 20000 73730 ns/op | |
BenchmarkSOA10000 30000 53874 ns/op | |
BenchmarkAOS32000 5000 258444 ns/op | |
Benchmark1AOS32000 5000 252986 ns/op | |
BenchmarkSOA32000 10000 172525 ns/op | |
BenchmarkAOS64000 3000 512123 ns/op | |
Benchmark1AOS64000 3000 529963 ns/op | |
BenchmarkSOA64000 5000 344711 ns/op | |
BenchmarkAOS128000 2000 1051982 ns/op | |
Benchmark1AOS128000 2000 1057272 ns/op | |
BenchmarkSOA128000 2000 707125 ns/op | |
ok github.com/apg/soa 37.471s |
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 soa | |
import ( | |
"math/rand" | |
) | |
type Vector3 struct { | |
x, y, z int | |
} | |
type AVector3 struct { | |
x []int | |
y []int | |
z []int | |
} | |
func ToSOA(vs []Vector3) AVector3 { | |
out := AVector3{ | |
x: make([]int, len(vs)), | |
y: make([]int, len(vs)), | |
z: make([]int, len(vs)), | |
} | |
for i, v := range vs { | |
out.x[i] = v.x | |
out.y[i] = v.x | |
out.z[i] = v.x | |
} | |
return out | |
} | |
func randomVector3s(max int) []Vector3 { | |
out := make([]Vector3, max) | |
for i := 0; i < max; i++ { | |
out[i].x = rand.Int() | |
out[i].y = rand.Int() | |
out[i].z = rand.Int() | |
} | |
return out | |
} |
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 soa | |
import "testing" | |
var vs10 []Vector3 | |
var avs10 AVector3 | |
var vs100 []Vector3 | |
var avs100 AVector3 | |
var vs1000 []Vector3 | |
var avs1000 AVector3 | |
var vs10000 []Vector3 | |
var avs10000 AVector3 | |
var vs32000 []Vector3 | |
var avs32000 AVector3 | |
var vs64000 []Vector3 | |
var avs64000 AVector3 | |
var vs128000 []Vector3 | |
var avs128000 AVector3 | |
func init() { | |
vs10 = randomVector3s(10) | |
avs10 = ToSOA(vs10) | |
vs100 = randomVector3s(100) | |
avs100 = ToSOA(vs100) | |
vs1000 = randomVector3s(1000) | |
avs1000 = ToSOA(vs1000) | |
vs10000 = randomVector3s(10000) | |
avs10000 = ToSOA(vs10000) | |
vs32000 = randomVector3s(32000) | |
avs32000 = ToSOA(vs32000) | |
vs64000 = randomVector3s(64000) | |
avs64000 = ToSOA(vs64000) | |
vs128000 = randomVector3s(128000) | |
avs128000 = ToSOA(vs128000) | |
} | |
func bAOS(vs []Vector3, b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
sumX := 0 | |
sumY := 0 | |
sumZ := 0 | |
for j := 0; j < len(vs); j++ { | |
sumX += vs[j].x | |
} | |
for j := 0; j < len(vs); j++ { | |
sumY += vs[j].y | |
} | |
for j := 0; j < len(vs); j++ { | |
sumZ += vs[j].z | |
} | |
} | |
} | |
func b1AOS(vs []Vector3, b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
sumX := 0 | |
sumY := 0 | |
sumZ := 0 | |
for j := 0; j < len(vs); j++ { | |
sumX += vs[j].x | |
sumY += vs[j].y | |
sumZ += vs[j].z | |
} | |
} | |
} | |
func bSOA(avs AVector3, b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
sumX := 0 | |
sumY := 0 | |
sumZ := 0 | |
for j := 0; j < len(avs.x); j++ { | |
sumX += avs.x[j] | |
} | |
for j := 0; j < len(avs.y); j++ { | |
sumY += avs.y[j] | |
} | |
for j := 0; j < len(avs.z); j++ { | |
sumZ += avs.z[j] | |
} | |
} | |
} | |
func BenchmarkAOS10(b *testing.B) { bAOS(vs10, b) } | |
func Benchmark1AOS10(b *testing.B) { bAOS(vs10, b) } | |
func BenchmarkSOA10(b *testing.B) { bSOA(avs10, b) } | |
func BenchmarkAOS100(b *testing.B) { bAOS(vs100, b) } | |
func Benchmark1AOS100(b *testing.B) { bAOS(vs100, b) } | |
func BenchmarkSOA100(b *testing.B) { bSOA(avs100, b) } | |
func BenchmarkAOS1000(b *testing.B) { bAOS(vs1000, b) } | |
func Benchmark1AOS1000(b *testing.B) { bAOS(vs1000, b) } | |
func BenchmarkSOA1000(b *testing.B) { bSOA(avs1000, b) } | |
func BenchmarkAOS10000(b *testing.B) { bAOS(vs10000, b) } | |
func Benchmark1AOS10000(b *testing.B) { bAOS(vs10000, b) } | |
func BenchmarkSOA10000(b *testing.B) { bSOA(avs10000, b) } | |
func BenchmarkAOS32000(b *testing.B) { bAOS(vs32000, b) } | |
func Benchmark1AOS32000(b *testing.B) { bAOS(vs32000, b) } | |
func BenchmarkSOA32000(b *testing.B) { bSOA(avs32000, b) } | |
func BenchmarkAOS64000(b *testing.B) { bAOS(vs64000, b) } | |
func Benchmark1AOS64000(b *testing.B) { bAOS(vs64000, b) } | |
func BenchmarkSOA64000(b *testing.B) { bSOA(avs64000, b) } | |
func BenchmarkAOS128000(b *testing.B) { bAOS(vs128000, b) } | |
func Benchmark1AOS128000(b *testing.B) { bAOS(vs128000, b) } | |
func BenchmarkSOA128000(b *testing.B) { bSOA(avs128000, b) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment