Permalink
Browse files

moved tests around a bit

  • Loading branch information...
1 parent c8234d4 commit 19673e7deaeea86a3cb5273b342c6d790bed8bbe Peter Ohler committed Feb 24, 2012
View
@@ -278,7 +278,7 @@ add_element(PInfo pi, const char *ename, Attr attrs, int hasChildren) {
VALUE sym;
VALUE *slot;
- if (Qundef == (sym = ox_cache_get(symbol_cache, attrs->name, &slot))) {
+ if (Qundef == (sym = ox_cache_get(ox_symbol_cache, attrs->name, &slot))) {
#ifdef HAVE_RUBY_ENCODING_H
if (0 != pi->encoding) {
VALUE rstr = rb_str_new2(attrs->name);
View
@@ -104,7 +104,7 @@ name2var(const char *name, void *encoding) {
if ('0' <= *name && *name <= '9') {
var_id = INT2NUM(atoi(name));
- } else if (Qundef == (var_id = ox_cache_get(attr_cache, name, &slot))) {
+ } else if (Qundef == (var_id = ox_cache_get(ox_attr_cache, name, &slot))) {
#ifdef HAVE_RUBY_ENCODING_H
if (0 != encoding) {
VALUE rstr = rb_str_new2(name);
@@ -210,7 +210,7 @@ classname2class(const char *name, PInfo pi) {
VALUE *slot;
VALUE clas;
- if (Qundef == (clas = ox_cache_get(class_cache, name, &slot))) {
+ if (Qundef == (clas = ox_cache_get(ox_class_cache, name, &slot))) {
char class_name[1024];
char *s;
const char *n = name;
@@ -451,7 +451,7 @@ add_text(PInfo pi, char *text, int closed) {
VALUE sym;
VALUE *slot;
- if (Qundef == (sym = ox_cache_get(symbol_cache, text, &slot))) {
+ if (Qundef == (sym = ox_cache_get(ox_symbol_cache, text, &slot))) {
sym = str2sym(text, pi->encoding);
*slot = sym;
}
@@ -503,7 +503,7 @@ add_text(PInfo pi, char *text, int closed) {
}
}
from_base64(text, (u_char*)str);
- if (Qundef == (sym = ox_cache_get(symbol_cache, str, &slot))) {
+ if (Qundef == (sym = ox_cache_get(ox_symbol_cache, str, &slot))) {
sym = str2sym(str, pi->encoding);
*slot = sym;
}
View
@@ -114,9 +114,9 @@ VALUE ox_bag_clas;
VALUE struct_class;
VALUE time_class;
-Cache symbol_cache = 0;
-Cache class_cache = 0;
-Cache attr_cache = 0;
+Cache ox_symbol_cache = 0;
+Cache ox_class_cache = 0;
+Cache ox_attr_cache = 0;
struct _Options default_options = {
{ '\0' }, // encoding
@@ -709,9 +709,9 @@ void Init_ox() {
ox_cdata_clas = rb_const_get_at(Ox, rb_intern("CData"));
ox_bag_clas = rb_const_get_at(Ox, rb_intern("Bag"));
- ox_cache_new(&symbol_cache);
- ox_cache_new(&class_cache);
- ox_cache_new(&attr_cache);
+ ox_cache_new(&ox_symbol_cache);
+ ox_cache_new(&ox_class_cache);
+ ox_cache_new(&ox_attr_cache);
rb_define_module_function(Ox, "cache_test", cache_test, 0);
rb_define_module_function(Ox, "cache8_test", cache8_test, 0);
View
@@ -264,9 +264,9 @@ extern VALUE ox_comment_clas;
extern VALUE ox_doctype_clas;
extern VALUE ox_cdata_clas;
-extern Cache symbol_cache;
-extern Cache class_cache;
-extern Cache attr_cache;
+extern Cache ox_symbol_cache;
+extern Cache ox_class_cache;
+extern Cache ox_attr_cache;
#if defined(__cplusplus)
#if 0
View
@@ -174,7 +174,7 @@ str2sym(const char *str, SaxDrive dr) {
VALUE *slot;
VALUE sym;
- if (Qundef == (sym = ox_cache_get(symbol_cache, str, &slot))) {
+ if (Qundef == (sym = ox_cache_get(ox_symbol_cache, str, &slot))) {
#ifdef HAVE_RUBY_ENCODING_H
if (0 != dr->encoding) {
VALUE rstr = rb_str_new2(str);
View
@@ -8,27 +8,22 @@
end
require 'pp'
-require 'ox'
-require 'test/ox/file'
-require 'test/ox/dir'
+require 'sample/file'
+require 'sample/dir'
def files(dir)
- d = ::Test::Ox::Dir.new(dir)
+ d = ::Sample::Dir.new(dir)
Dir.new(dir).each do |fn|
next if fn.start_with?('.')
filename = File.join(dir, fn)
#filename = '.' == dir ? fn : File.join(dir, fn)
if File.directory?(filename)
d << files(filename)
else
- d << Test::Ox::File.new(filename)
+ d << ::Sample::File.new(filename)
end
end
#pp d
d
end
-if $0 == __FILE__
- File.open('files.xml', "w") { |f| f.write(Ox.dump(files('.'), :indent => 2, :opt_format => true)) }
- #Ox.to_file(files('.'), 'files2.xml', :indent => 2, :opt_format => true)
-end
View
@@ -0,0 +1,91 @@
+
+class Perf
+
+ def initialize()
+ @items = []
+ end
+
+ def add(title, op, &blk)
+ @items << Item.new(title, op, &blk)
+ end
+
+ def run(iter)
+ base = Item.new(nil, nil) { }
+ base.run(iter, 0.0)
+ @items.each do |i|
+ i.run(iter, base.duration)
+ if i.error.nil?
+ puts "#{i.title}.#{i.op} #{iter} times in %0.3f seconds or %0.3f #{i.op}/sec." % [i.duration, iter / i.duration]
+ else
+ puts "***** #{i.title}.#{i.op} failed! #{i.error}"
+ end
+ end
+ summary()
+ end
+
+ def summary()
+ fastest = nil
+ slowest = nil
+ width = 6
+ @items.each do |i|
+ next if i.duration.nil?
+ width = i.title.size if width < i.title.size
+ end
+ iva = @items.clone
+ iva.delete_if { |i| i.duration.nil? }
+ iva.sort_by! { |i| i.duration }
+ puts
+ puts "Summary:"
+ puts "%*s time (secs) rate (ops/sec)" % [width, 'System']
+ puts "#{'-' * width} ----------- --------------"
+ iva.each do |i|
+ if i.duration.nil?
+ else
+ puts "%*s %11.3f %14.3f" % [width, i.title, i.duration, i.rate ]
+ end
+ end
+ puts
+ puts "Comparison Matrix\n(performance factor, 2.0 row is means twice as fast as column)"
+ puts ([' ' * width] + iva.map { |i| "%*s" % [width, i.title] }).join(' ')
+ puts (['-' * width] + iva.map { |i| '-' * width }).join(' ')
+ iva.each do |i|
+ line = ["%*s" % [width, i.title]]
+ iva.each do |o|
+ line << "%*.2f" % [width, o.duration / i.duration]
+ end
+ puts line.join(' ')
+ end
+ puts
+ end
+
+ class Item
+ attr_accessor :title
+ attr_accessor :op
+ attr_accessor :blk
+ attr_accessor :duration
+ attr_accessor :rate
+ attr_accessor :error
+
+ def initialize(title, op, &blk)
+ @title = title
+ @blk = blk
+ @op = op
+ @duration = nil
+ @rate = nil
+ @error = nil
+ end
+
+ def run(iter, base)
+ begin
+ start = Time.now
+ iter.times { @blk.call }
+ @duration = Time.now - start - base
+ @duration = 0.0 if @duration < 0.0
+ @rate = iter / @duration
+ rescue Exception => e
+ @error = "#{e.class}: #{e.message}"
+ end
+ end
+
+ end # Item
+end # Perf
Oops, something went wrong.

0 comments on commit 19673e7

Please sign in to comment.