What is the kernel in the Code Sea?
-------------------------
-------------------------
-------------------------
-------------------------
ruby on rails的cache机制下, 两者可以互换
-------------------------
#! /usr/bin/ruby
a={}
i=0
while i<600000 do
a=i
i+=1
end
a.each do |i|
a.key? i
end
apple@mysite:~$ time ./test.rb
real 0m1.321s
user 0m1.268s
sys 0m0.036s
-------------------------
#! /usr/bin/ruby
a={}
for i in 0...600000
a=i
end
a.each do |k|
a.key? k
end
apple@mysite:~$ time ./test.rb
real 0m1.322s
user 0m1.292s
sys 0m0.020s
-------------------------
可能底层数据类型不一样
你用的是索引数组 我用的是关联数组
如果是索引数组,
array_key_exists($i, $a);
这个语句意义和我的不一样
-------------------------
package main
go语言也测试了一下
func main(){
a :=map[int]int{}
for i:=0;i<600000;i++ {
a=i
}
for i,_ :=range a {
_,_=a
}
}
$ time go run test.go
real 0m0.349s
user 0m0.208s
sys 0m0.040s
忘编译了
apple@mysite:~$ go build test.go
apple@mysite:~$ time ./test
real 0m0.195s
user 0m0.184s
sys 0m0.008s