Added some more tests for c file wraps.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9928 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d1defceb95
commit
8682f0cbaf
6 changed files with 252 additions and 0 deletions
67
Examples/test-suite/ruby/li_std_speed2_runme.rb
Executable file
67
Examples/test-suite/ruby/li_std_speed2_runme.rb
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'benchmark'
|
||||
require 'li_std_speed'
|
||||
include Li_std_speed
|
||||
|
||||
def benchmark(f, phigh, sequences)
|
||||
print f.class
|
||||
puts '%10s ' % 'n' + sequences.inject('') { |a,s| a << '%10s' % s.class }
|
||||
0.upto(phigh-1) do |p|
|
||||
n = 2**p
|
||||
print "%10d"%n
|
||||
$stdout.flush
|
||||
for s in sequences
|
||||
cont = s.new((0..n).to_a)
|
||||
Benchmark.benchmark { f.call(cont) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def iterate(cont)
|
||||
# expected: O(n)
|
||||
# got: O(n**2) for set/list (vector/deque fine)
|
||||
it = cont.begin
|
||||
last = cont.end
|
||||
while it != last
|
||||
it.next
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def erase(cont)
|
||||
# expected: O(n)
|
||||
# got: O(n**2) for vector/deque and O(n**3) for set/list
|
||||
it = cont.end
|
||||
# can't reuse begin since it might get invalidated
|
||||
while it != cont.begin
|
||||
it.previous
|
||||
# set returns None, so need to reobtain end
|
||||
it = cont.erase(it) or cont.end
|
||||
end
|
||||
end
|
||||
|
||||
def insert(cont)
|
||||
it = cont.end
|
||||
size = cont.size
|
||||
if cont.kind_of? RbSet
|
||||
# swig stl missing hint version of insert for set
|
||||
# expected would be O(n) with iterator hint version
|
||||
# expected: O(n*log(n))
|
||||
# got: O(n**3*log(n))
|
||||
size.upto(size<<1) { |x| cont.insert(x) }
|
||||
else
|
||||
# expected: O(n)
|
||||
# got: O(n**3) for list (vector/deque fine)
|
||||
size.upto(size<<1) { |x| cont.push(x) }
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
sequences = [RbVector,RbDeque,RbSet,RbList]
|
||||
for f,phigh in [[method(:iterate),15], [method(:insert),15],
|
||||
[method(:erase),11]]
|
||||
benchmark(f, phigh, sequences)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue