bg5sbk / go-labs Goto Github PK
View Code? Open in Web Editor NEW杂七杂八的Go语言实验代码
杂七杂八的Go语言实验代码
RT
测试环境的数据分布在连续内存中:
func init() {
for i := 0; i < 1000; i++ {
var newData = new(BigStruct)
newData.C30 = i
newData.next = data
data = newData
}
}
真实环境中,玩家数据在内存中的分布可能不是连续的
func init_cache_miss() {
for i := 0; i < 1800; i++ {
var newData = new(BigStruct)
if i%5 >= 3 {
newData.C30 = i
newData.next = otherUserData
otherUserData = newData
} else {
newData.C30 = i
newData.next = data
data = newData
}
}
}
原始版本:
PASS
Benchmark_Loop1-8 300000 5156 ns/op
Benchmark_Loop2-8 200000 5891 ns/op
Benchmark_Loop3-8 100000 14506 ns/op
Benchmark_Loop4-8 20000 95709 ns/op
Benchmark_Loop5-8 3000 447557 ns/op
Benchmark_Loop6-8 200000 8395 ns/op
Benchmark_Loop7-8 200000 9301 ns/op
ok go-labs/labs07 12.440s
模拟 cache miss 情况
PASS
Benchmark_Loop1-8 200000 9960 ns/op
Benchmark_Loop2-8 200000 10466 ns/op
Benchmark_Loop3-8 100000 18221 ns/op
Benchmark_Loop4-8 10000 107809 ns/op
Benchmark_Loop5-8 3000 507910 ns/op
Benchmark_Loop6-8 200000 11533 ns/op
Benchmark_Loop7-8 200000 11954 ns/op
ok go-labs/labs07 13.934s
我觉得还是 slice 效率更优。因为 slice 可以保证同一个玩家的数据在一段连续内存。
labs09_test.go
testing: warning: no tests to run
PASS
Benchmark_NormalFuncCall 2000000000 0.68 ns/op
Benchmark_VarFuncCall1 1000000000 2.37 ns/op
Benchmark_VarFuncCall2 1000000000 2.83 ns/op
ok github.com/realint/labs/src/labs09 7.195s
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.