| 
 
| 赞 | 0 |  
| VIP | 0 |  
| 好人卡 | 1 |  
| 积分 | 1 |  
| 经验 | 7590 |  
| 最后登录 | 2014-11-28 |  
| 在线时间 | 135 小时 |  
 Lv1.梦旅人 
	梦石0 星屑50 在线时间135 小时注册时间2013-6-10帖子29 | 
| 本帖最后由 xTsukihime 于 2013-10-3 01:40 编辑 
 我建議意思是 ”0.1<= a和 a <= 0.5“
 而且比別的快2-4倍
 复制代码require 'Benchmark'
a = 0.2
n = 100000
Benchmark.bm {|x|
  x.report { n.times{a.between?(0.1,0.5)}}
  x.report { n.times{(0.1..0.5)===a}}
  x.report { n.times{(0.1..0.5).member?a}}
  x.report { n.times{(0.1..0.5).include?a}}
  x.report { n.times{ 0.1 <= a && a <= 0.5}}
}
复制代码       user     system      total        real
   0.047000   0.000000   0.047000 (  0.034002)
   0.078000   0.000000   0.078000 (  0.088005)
   0.078000   0.000000   0.078000 (  0.081004)
   0.093000   0.000000   0.093000 (  0.081005)
   0.016000   0.000000   0.016000 (  0.025001)
 | 
 评分
查看全部评分
 |