1 # require 'profile'
 2 require 'druby2'
 3 
 4 client = DRuby::Client.new('localhost', '4242', false)
 5 obj = client.resolve("foo")
 6 
 7 N = 10000
 8 
 9 puts "Normal functions, no synchronization"
10 start_time = Time.now
11 (1..N).each do |i|
12     obj.foo(i)
13 end
14 obj.sync()
15 total_time = Time.now - start_time
16 puts "  Total time: #{total_time}"
17 puts "  Messages per second: #{N/total_time}"
18 
19 # TODO: For some reason, mixing normal function calls with oneway calls
20 # causes the oneways to run at 1/10 regular speed
21 client = DRuby::Client.new('localhost', '4242', false)
22 obj = client.resolve("foo")
23 
24 puts "Oneway functions, no synchronization"
25 start_time = Time.now
26 (1..N).each do |i|
27     obj.oneway(:foo, i)
28 end
29 obj.sync()
30 total_time = Time.now - start_time
31 puts "  Total time: #{total_time}"
32 puts "  Messages per second: #{N/total_time}"
33 
34 puts "You should see the number #{N}:"
35 puts obj.bar()
36 
37 puts "You should see an object Foo with an element @i=#{N}"
38 puts obj.inspect()
39 
40 foo = obj.methods()
41 if foo.index("dup") then
42     puts "uh oh, shouldn't have found dup"
43 end
44 
45 if obj.respond_to?("clone") then
46     puts "uh oh, obj should not respond to clone"
47 end
48 
49 except = false
50 begin
51     obj.clone()
52 rescue NameError
53     except = true
54 end
55 if !except then
56     puts "uh oh, I was able to clone obj"
57 end
58 
59 if !obj.respond_to?("foo") then
60     puts "uh oh, obj should respond to foo!"
61 end
62 
63 puts "You should see the numbers 1, 2, and 3 on separate lines:"
64 obj.each do |i|
65     puts i
66 end
67 
68 puts "You should now see a RuntimeError get thrown:"
69 obj.throw_exception()