summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-12 04:38:50 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-12 04:38:50 +0000
commit3c9187a2ad892d0c7c4b905104bb71c3c34a999e (patch)
tree743674bae1c1af7a43e9412155be9969d46d0db2 /benchmark
parent60e078c860eed4ed92aa7be556623a52bf218f1b (diff)
* benchmark/bm_vm3_thread_mutex.rb: remove it.
* benchmark/bm_vm3_thread_mutex[1-3].rb: added 3 benchmarks. 1: one thread with one mutex (no contention). 2: two threads with one mutex (contention). 3: 1000 threads with one mutex (huge number of contention) Abobe removed benchmark was type 3. Therefore, this commit adds type 1 and 2 benchmark. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/bm_vm3_thread_mutex1.rb21
-rw-r--r--benchmark/bm_vm3_thread_mutex2.rb21
-rw-r--r--benchmark/bm_vm3_thread_mutex3.rb (renamed from benchmark/bm_vm3_thread_mutex.rb)38
3 files changed, 62 insertions, 18 deletions
diff --git a/benchmark/bm_vm3_thread_mutex1.rb b/benchmark/bm_vm3_thread_mutex1.rb
new file mode 100644
index 0000000..d1ba792
--- /dev/null
+++ b/benchmark/bm_vm3_thread_mutex1.rb
@@ -0,0 +1,21 @@
+# one thread, one mutex (no contention)
+
+require 'thread'
+m = Mutex.new
+r = 0
+max = 1000
+lmax = max * max
+(1..1).map{
+ Thread.new{
+ i=0
+ while i<lmax
+ i+=1
+ m.synchronize{
+ r += 1
+ }
+ end
+ }
+}.each{|e|
+ e.join
+}
+raise r.to_s if r != max * max
diff --git a/benchmark/bm_vm3_thread_mutex2.rb b/benchmark/bm_vm3_thread_mutex2.rb
new file mode 100644
index 0000000..2903845
--- /dev/null
+++ b/benchmark/bm_vm3_thread_mutex2.rb
@@ -0,0 +1,21 @@
+# two threads, one mutex
+
+require 'thread'
+m = Mutex.new
+r = 0
+max = 1000
+lmax = (max * max)/2
+(1..2).map{
+ Thread.new{
+ i=0
+ while i<lmax
+ i+=1
+ m.synchronize{
+ r += 1
+ }
+ end
+ }
+}.each{|e|
+ e.join
+}
+raise r.to_s if r != max * max
diff --git a/benchmark/bm_vm3_thread_mutex.rb b/benchmark/bm_vm3_thread_mutex3.rb
index 649f1fd..888ae8e 100644
--- a/benchmark/bm_vm3_thread_mutex.rb
+++ b/benchmark/bm_vm3_thread_mutex3.rb
@@ -1,18 +1,20 @@
-require 'thread'
-m = Mutex.new
-r = 0
-max = 1000
-(1..max).map{
- Thread.new{
- i=0
- while i<max
- i+=1
- m.synchronize{
- r += 1
- }
- end
- }
-}.each{|e|
- e.join
-}
-raise r.to_s if r != max * max
+# 1000 threads, one mutex
+
+require 'thread'
+m = Mutex.new
+r = 0
+max = 1000
+(1..max).map{
+ Thread.new{
+ i=0
+ while i<max
+ i+=1
+ m.synchronize{
+ r += 1
+ }
+ end
+ }
+}.each{|e|
+ e.join
+}
+raise r.to_s if r != max * max