Added new speed test and minor cosmetic fixes to

other older tests.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9826 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Gonzalo Garramuno 2007-05-19 09:49:19 +00:00
commit 597f650d02
5 changed files with 89 additions and 3 deletions

View file

@ -5,6 +5,7 @@
%include <std_list.i>
%include <std_set.i>
%include <std_map.i>
%include <std_functors.i>
%template(Vector ) std::vector <swig::LANGUAGE_OBJ>;
%template(Deque ) std::deque <swig::LANGUAGE_OBJ>;

View file

@ -26,13 +26,13 @@ sum == 'abc'
b = s.begin # only if swig iterators are on
e = s.end
sum = ''
while b != e; sum << b.next; end
while b != e; sum << b.value; b.next; end
sum == 'abc'
b = s.rbegin # only if swig iterators are on
e = s.rend
sum = ''
while b != e; sum << b.next; end
while b != e; sum << b.value; b.next; end
sum == 'cba'

View file

@ -0,0 +1,21 @@
/**
* @file li_std_speed.i
* @author gga
* @date Fri May 18 18:03:15 2007
*
* @brief A speed test of the ruby stl
*
*
*/
%module li_std_speed
%include <std_list.i>
%include <std_vector.i>
%include <std_deque.i>
%include <std_set.i>
%template(RbList) std::list<swig::GC_VALUE>;
%template(RbVector) std::vector<swig::GC_VALUE>;
%template(RbDeque) std::deque<swig::GC_VALUE>;
%template(RbSet) std::set<swig::GC_VALUE>;

View file

@ -0,0 +1,64 @@
#!/usr/bin/env ruby
require 'benchmark'
require 'li_std_speed'
include Li_std_speed
def benchmark(f, phigh, sequences)
puts f
print '%10s ' % 'n'
sequences.each { |s| print "%10s" % "#{s.to_s.sub(/.*::/,'')}" }
puts
0.upto(phigh-1) do |p|
n = 2**p
print "%10d" % n
for s in sequences
cont = s.new((0..n).to_a)
Benchmark.benchmark('',0,'%9.6r') { |x| x.report { f.call(cont) } }
end
puts
end
end
def iterate(cont)
it = cont.begin
last = cont.end
while it != last
it.next
end
end
def erase(cont)
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) || cont.end
end
end
def insert(cont)
it = cont.end
size = cont.size
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
if $0 == __FILE__
sequences = [RbVector,RbDeque,RbSet,RbList]
n = 15
for f,phigh in [[method(:iterate),n], [method(:insert),n],
[method(:erase),n-4]]
benchmark(f, phigh, sequences)
end
end

View file

@ -52,7 +52,7 @@ im = midentb(m)
mi = Imatrix.new(m)
mc = Cmatrix.new(m)
mi[0][1] == mc[0][1] # or bad matrix
mi[0][0] == mc[0][0] # or bad matrix
map ={}
map['hello'] = 1