Module: Bench

Defined in:
lib/xamplr/test-support/bench.rb,
lib/xamplr/test-support/bench2.rb,
lib/xamplr/test-support/bench-cache.rb

Overview

require ‘persister/fsdb’

Class Method Summary collapse

Class Method Details

.goObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/xamplr/test-support/bench.rb', line 33

def Bench.go
  count = 1000

  emph_content_1 = "there"
  emph1 = Emph.new
  emph1 << emph_content_1

  emph_content_2 = "are"
  emph2 = Emph.new
  emph2.content = emph_content_2

  desc1 = Description.new
  desc1.kind = "desc1"

  desc1.is_changed = nil
  desc1 << "hello " << emph1 << "! How " << emph2 << " you?"

  thing = Thing.new
  thing.pid = "thing"
  thing.new_stuff.kind = "stuff1"
  thing << desc1

  big_thing = Thing.new
  big_thing << thing

  #require "to-ruby"
  #ruby_printer = RubyPrinter.new
  #ruby_s = ruby_printer.to_ruby(thing)
  ruby_s = thing.to_ruby
  xml_s = thing.persist

  puts xml_s
  puts ruby_s
  puts "++++++++++++++++++++++++++++++++++++"
  puts "big_thing #{big_thing.object_id}, thing #{thing.object_id}"
  puts big_thing.to_ruby
  puts "++++++++++++++++++++++++++++++++++++"

  puts "Rebuilding From String (XML) count: #{count} (est. ~ 11s)"
  bm(10) do | x |
    x.report("xml") {
      count.times {
        another_big_thing = XamplObject.from_xml_string(xml_s)
      }
    }
    x.report("ruby") {
      count.times {
        XamplObject.from_ruby(ruby_s)
      }
    }
  end

  puts "Serialize to String (XML) count: #{count} (est. ~ 25s)"
  bm(10) do | x |
    x.report("xml") {
      count.times {
        xml_s = thing.persist
      }
    }
    x.report("ruby") {
      count.times {
        ruby_s = thing.to_ruby
      }
    }
  end

  puts "Round Tripping (XML) count: #{count} (est. ~ 40s)"
  bm(10) do | x |
    x.report("xml") {
      count.times {
        another_thing = XamplObject.from_xml_string(thing.persist)
      }
    }
    x.report("ruby") {
      count.times {
        XamplObject.from_ruby(thing.to_ruby)
      }
    }
  end
end

.make_a_thing(pid) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/xamplr/test-support/bench2.rb', line 105

def Bench.make_a_thing(pid)
  emph_content_1 = "there"
  emph1 = Emph.new
  emph1 << emph_content_1

  emph_content_2 = "are"
  emph2 = Emph.new
  emph2.content = emph_content_2

  desc1 = Description.new
  desc1.kind = "desc1"

  desc1.is_changed = nil
  desc1 << "hello " << emph1 << "! How " << emph2 << " you?"

  thing = Thing.new
  thing.pid = pid
  thing.info = pid
  thing.new_stuff.kind = "stuff1"
  thing << desc1

  return thing
end

.no_rollbacks(count_things, count) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/xamplr/test-support/bench2.rb', line 65

def Bench.no_rollbacks(count_things, count)
  writes = 0
  things = []
  count_things.times { | i |
    thing = Bench.make_a_thing("thing-#{i}")
    Xampl.introduce_to_persister(thing)
    things << thing
  }

  things.each{ | thing | Xampl.introduce_to_persister(thing) }
  count.times { | time |
    things.each{ | thing |
      thing.info = [thing.pid, time].join
    }
    writes += Xampl.sync
  }
  return writes
end

.rollbacks(count_things, count) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/xamplr/test-support/bench2.rb', line 84

def Bench.rollbacks(count_things, count)
  writes = 0
  things = []
  count_things.times { | i |
    thing = Bench.make_a_thing("thing-#{i}")
    Xampl.introduce_to_persister(thing)
    things << thing
  }

  things.each{ | thing | Xampl.introduce_to_persister(thing) }
  count.times { | time |
    writes += Xampl.sync
    Xampl.rollback

    things.each{ | thing |
      thing.info = [thing.pid, time].join
    }
  }
  return writes
end