Kenji Okimoto
okimo****@clear*****
Tue Mar 18 10:18:48 JST 2014
配列への要素の追加で、速度を求めるなら + よりも << か push を使った方がいいと思います。
# 配列ではなかったら、すみません。。。
$ cat a.rb
require "benchmark"
a = []
b = []
c = []
Benchmark.bmbm do |x|
x.report("+"){ 100000.times{|n| a += [n] }}
x.report("push"){ 100000.times{|n| b.push(n) }}
x.report("<<"){100000.times{|n| c << n } }
end
$ ruby a.rb
Rehearsal ----------------------------------------
+ 7.880000 1.530000 9.410000 ( 9.412625)
push 0.010000 0.000000 0.010000 ( 0.008801)
<< 0.000000 0.000000 0.000000 ( 0.006635)
------------------------------- total: 9.420000sec
user system total real
+ 36.050000 8.680000 44.730000 ( 44.744900)
push 0.010000 0.000000 0.010000 ( 0.008950)
<< 0.010000 0.000000 0.010000 ( 0.006551)
(2014年03月17日 22:45), Kouhei Sutou wrote:
> Author
> Kouhei Sutou <kou �� clear-code.com>
> Date
> 2014-03-17 22:45:15 +0900 (Mon, 17 Mar 2014)
> New Revision
> 1e5b5a1f4dfd412e3381a78777be078eff9ad285 <https://github.com/droonga/fluent-plugin-droonga/commit/1e5b5a1f4dfd412e3381a78777be078eff9ad285>
> Message
>
> Simplify
>
> Modified files
>
> * lib/droonga/distributed_command_planner.rb <https://github.com/droonga/fluent-plugin-droonga/commit/1e5b5a1f4dfd412e3381a78777be078eff9ad285#diff-0>
>
> Modified: lib/droonga/distributed_command_planner.rb (+3 -3)
> ===================================================================
>
>
>
> @@ -100,8 +100,8 @@module Droonga
> unified = unified_reducers[type]
> if unified
> unified["body"] = unified["body"].merge(reducer["body"])
> - unified["inputs"] = unified["inputs"] + reducer["inputs"]
> - unified["outputs"] = unified["outputs"] + reducer["outputs"]
> + unified["inputs"] += reducer["inputs"]
> + unified["outputs"] += reducer["outputs"]
> else
> unified_reducers[type] = reducer.dup
> end
> @@ -116,7 +116,7 @@module Droonga
> unified = unified_gatherers[type]
> if unified
> unified["body"] = unified["body"].merge(gatherer["body"])
> - unified["inputs"] = unified["inputs"] + gatherer["inputs"]
> + unified["inputs"] += gatherer["inputs"]
> else
> unified_gatherers[type] = gatherer.dup
> end
>
>
>
> _______________________________________________
> Groonga-commit mailing list
> Groonga-commit �� lists.sourceforge.jp
> http://lists.sourceforge.jp/mailman/listinfo/groonga-commit
>
--
Kenji Okimoto <okimoto �� clear-code.com>