Updated li_std_speed.i to also test speed of
container with an actual class (float). Simplified insert() function. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9831 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
32b10ee9b7
commit
1d35a3bb0e
2 changed files with 27 additions and 16 deletions
|
|
@ -19,3 +19,8 @@
|
||||||
%template(RbVector) std::vector<swig::GC_VALUE>;
|
%template(RbVector) std::vector<swig::GC_VALUE>;
|
||||||
%template(RbDeque) std::deque<swig::GC_VALUE>;
|
%template(RbDeque) std::deque<swig::GC_VALUE>;
|
||||||
%template(RbSet) std::set<swig::GC_VALUE>;
|
%template(RbSet) std::set<swig::GC_VALUE>;
|
||||||
|
|
||||||
|
%template(RbFloatList) std::list<float>;
|
||||||
|
%template(RbFloatVector) std::vector<float>;
|
||||||
|
%template(RbFloatDeque) std::deque<float>;
|
||||||
|
%template(RbFloatSet) std::set<float>;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,12 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
#
|
||||||
|
# This is a simple speed benchmark suite for std containers,
|
||||||
|
# to verify their O(n) performance.
|
||||||
|
# It is not part of the standard tests.
|
||||||
|
#
|
||||||
|
# License:: SWIG
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
require 'benchmark'
|
require 'benchmark'
|
||||||
require 'li_std_speed'
|
require 'li_std_speed'
|
||||||
|
|
@ -8,14 +16,18 @@ include Li_std_speed
|
||||||
def benchmark(f, phigh, sequences)
|
def benchmark(f, phigh, sequences)
|
||||||
puts f
|
puts f
|
||||||
print '%10s ' % 'n'
|
print '%10s ' % 'n'
|
||||||
sequences.each { |s| print "%10s" % "#{s.to_s.sub(/.*::/,'')}" }
|
maxlen = sequences.max { |a,b| a.to_s.size <=> b.to_s.size }
|
||||||
|
maxlen = maxlen.to_s.size - 9
|
||||||
|
sequences.each { |s| print "%#{maxlen}s" % "#{s.to_s.sub(/.*::/,'')}" }
|
||||||
puts
|
puts
|
||||||
0.upto(phigh-1) do |p|
|
0.upto(phigh-1) do |p|
|
||||||
n = 2**p
|
n = 2**p
|
||||||
print "%10d" % n
|
print "%10d" % n
|
||||||
for s in sequences
|
for s in sequences
|
||||||
cont = s.new((0..n).to_a)
|
cont = s.new((0..n).to_a)
|
||||||
Benchmark.benchmark('',0,'%9.6r') { |x| x.report { f.call(cont) } }
|
Benchmark.benchmark('',0,"%#{maxlen-1}.6r") { |x|
|
||||||
|
x.report { f.call(cont) }
|
||||||
|
}
|
||||||
end
|
end
|
||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
|
|
@ -41,21 +53,15 @@ def erase(cont)
|
||||||
end
|
end
|
||||||
|
|
||||||
def insert(cont)
|
def insert(cont)
|
||||||
it = cont.end
|
size = cont.size
|
||||||
size = cont.size
|
size.upto((size<<1) - 1) { |x| cont.push(x) }
|
||||||
if cont.kind_of? RbSet
|
|
||||||
size.upto((size<<1) - 1) { |x| cont.insert(x) }
|
|
||||||
elsif cont.kind_of? RbVector
|
|
||||||
cont.reserve(size<<1)
|
|
||||||
size.upto((size<<1) - 1) { |x| cont.push(x) }
|
|
||||||
else
|
|
||||||
size.upto((size<<1) - 1) { |x| cont.push(x) }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if $0 == __FILE__
|
if $0 == __FILE__
|
||||||
sequences = [RbVector,RbDeque,RbSet,RbList]
|
#GC.disable
|
||||||
n = 15
|
sequences = [RbVector,RbDeque,RbSet,RbList,
|
||||||
|
RbFloatVector,RbFloatDeque,RbFloatSet,RbFloatList]
|
||||||
|
n = 20
|
||||||
for f,phigh in [[method(:iterate),n], [method(:insert),n],
|
for f,phigh in [[method(:iterate),n], [method(:insert),n],
|
||||||
[method(:erase),n-4]]
|
[method(:erase),n-4]]
|
||||||
benchmark(f, phigh, sequences)
|
benchmark(f, phigh, sequences)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue