tests/benchmark_dvector_reads.rb in tioga-1.11 vs tests/benchmark_dvector_reads.rb in tioga-1.13
- old
+ new
@@ -1,7 +1,9 @@
# A small benchmarking file for fancy_read and fast_fancy_read, just to make
# sure the latter deserves its name ;-)...
+#
+# Now the comparison between fancy_read and fast_fancy_read
require 'Dobjects/Dvector'
require 'benchmark'
require 'stringio'
require 'tempfile'
@@ -13,82 +15,58 @@
100000.times do |i|
f.puts "#{i*1.0}\t#{i**1.3}\t#{i**0.7}"
end
f.close
end
- x.report("fancy_read(100000):") do
+ x.report("fancy_read(100 000):") do
stream = File.open(f.path)
Dobjects::Dvector.fancy_read(stream, nil, 'default'=> 0.0).size
end
- x.report("fancy_read(100000, 2nd):") do
+ x.report("fancy_read(100 000), 2nd time:") do
stream = File.open(f.path)
Dobjects::Dvector.fancy_read(stream, nil, 'default'=> 0.0).size
end
- x.report("fast_fancy_read(100000):") do
+
+ # Trying pre-allocation.
+ x.report("fancy_read(100 000), preallocation to 1 :") do
stream = File.open(f.path)
- Dobjects::Dvector.fast_fancy_read(stream, {
- 'sep' => /\s+/,
- 'comments' => /^\s*\#/,
- 'skip_first' => 0,
- 'index_col' => false,
- 'remove_space' => true,
- 'default'=> 0.0}).size
+ Dobjects::Dvector.fancy_read(stream, nil, 'default'=> 0.0,
+ 'initial_size' => 1).size
end
- x.report("fast_fancy_read(100000, 2nd):") do
+ x.report("fancy_read(100 000), preallocation to 49999 :") do
stream = File.open(f.path)
- Dobjects::Dvector.fast_fancy_read(stream, {
- 'sep' => /\s+/,
- 'comments' => /^\s*\#/,
- 'skip_first' => 0,
- 'index_col' => false,
- 'remove_space' => true,
- 'default'=> 0.0}).size
+ Dobjects::Dvector.fancy_read(stream, nil, 'default'=> 0.0,
+ 'initial_size' => 49999).size
end
+ x.report("fancy_read(100 000), preallocation to 100 000 :") do
+ stream = File.open(f.path)
+ Dobjects::Dvector.fancy_read(stream, nil, 'default'=> 0.0,
+ 'initial_size' => 100000).size
+ end
+
# We create a smaller file:
f = Tempfile.new("data")
1000.times do |i|
f.puts "#{i*1.0}\t#{i**1.3}\t#{i**0.7}"
end
f.close
- x.report("fast_fancy_read(100 * 1000):") do
- stream = File.open(f.path)
- 100.times do
- Dobjects::Dvector.fast_fancy_read(stream, {
- 'sep' => /\s+/,
- 'comments' => /^\s*\#/,
- 'skip_first' => 0,
- 'index_col' => false,
- 'remove_space' => true,
- 'default'=> 0.0})
- end
- end
x.report("fancy_read(100 * 1000):") do
- stream = File.open(f.path)
100.times do
+ stream = File.open(f.path)
Dobjects::Dvector.fancy_read(stream, nil, 'default'=> 0.0)
end
end
# We use a StringIO
string = ""
x.report("string creation:") do
50000.times do |i|
- string += "#{i*1.0}\t#{i**1.3}\t#{i**0.7}\n"
+ string.concat("#{i*1.0}\t#{i**1.3}\t#{i**0.7}\n")
end
end
x.report("fancy_read(50000):") do
stream = StringIO.new(string)
Dobjects::Dvector.fancy_read(stream, nil, 'default'=> 0.0).size
- end
- x.report("fast_fancy_read(50000):") do
- stream = StringIO.new(string)
- Dobjects::Dvector.fast_fancy_read(stream, {
- 'sep' => /\s+/,
- 'comments' => /^\s*\#/,
- 'skip_first' => 0,
- 'index_col' => false,
- 'remove_space' => true,
- 'default'=> 0.0}).size
end
end