You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains 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
The reason will be displayed to describe this comment to others. Learn more.
Hi amatsuda,
I have check, File open and then read is faster.
Please check the benchmark
Benchmark.bm do |x|
1.9.3-p362 :006 > x.report { 1000.times do ; File.open("nginx.conf").read; end }
1.9.3-p362 :007?> end
user system total real
0.020000 0.010000 0.030000 ( 0.029208)
=> [ 0.020000 0.010000 0.030000 ( 0.029208)
]
1.9.3-p362 :008 > Benchmark.bm do |x|
1.9.3-p362 :009 > x.report { 10000.times do ; File.read("nginx.conf"); end }
1.9.3-p362 :010?> end
user system total real
0.150000 0.040000 0.190000 ( 0.197419)
=> [ 0.150000 0.040000 0.190000 ( 0.197419)
The reason will be displayed to describe this comment to others. Learn more.
@smondal thanks for the benchmark. In any case, this code is only executed when creating a new application and you have a ~/.railsrc file to add common options to new rails applications, so it shouldn't be a big deal.
9d2187e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi amatsuda,
I have check, File open and then read is faster.
Please check the benchmark
Benchmark.bm do |x|
1.9.3-p362 :006 > x.report { 1000.times do ; File.open("nginx.conf").read; end }
1.9.3-p362 :007?> end
user system total real
0.020000 0.010000 0.030000 ( 0.029208)
=> [ 0.020000 0.010000 0.030000 ( 0.029208)
]
1.9.3-p362 :008 > Benchmark.bm do |x|
1.9.3-p362 :009 > x.report { 10000.times do ; File.read("nginx.conf"); end }
1.9.3-p362 :010?> end
user system total real
0.150000 0.040000 0.190000 ( 0.197419)
=> [ 0.150000 0.040000 0.190000 ( 0.197419)
And I have checked it two three times.
9d2187e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smondal thanks for the benchmark. In any case, this code is only executed when creating a new application and you have a
~/.railsrc
file to add common options to new rails applications, so it shouldn't be a big deal.9d2187e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smondal Looks like you benchmarked
File.open + read
1000.times 🆚File.read
10000.times.9d2187e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @carlosantoniodasilva