[macruby-changes] [4994] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Dec 7 18:35:06 PST 2010


Revision: 4994
          http://trac.macosforge.org/projects/ruby/changeset/4994
Author:   lsansonetti at apple.com
Date:     2010-12-07 18:35:02 -0800 (Tue, 07 Dec 2010)
Log Message:
-----------
remove lib/dispatch layer

Removed Paths:
-------------
    MacRuby/trunk/lib/dispatch/
    MacRuby/trunk/lib/dispatch.rb
    MacRuby/trunk/sample-macruby/Scripts/gcd/benchmarks.rb
    MacRuby/trunk/sample-macruby/Scripts/gcd/dispatch_methods.rb
    MacRuby/trunk/sample-macruby/Scripts/gcd/dispatch_methods.sh
    MacRuby/trunk/sample-macruby/Scripts/gcd/ring_buffer.rb
    MacRuby/trunk/spec/macruby/library/dispatch/
    MacRuby/trunk/spec/macruby/tags/macruby/library/dispatch/

Deleted: MacRuby/trunk/lib/dispatch.rb
===================================================================
--- MacRuby/trunk/lib/dispatch.rb	2010-12-08 00:26:31 UTC (rev 4993)
+++ MacRuby/trunk/lib/dispatch.rb	2010-12-08 02:35:02 UTC (rev 4994)
@@ -1,19 +0,0 @@
-# 
-# dispatch.rb - Grand Central Dispatch support library
-# 
-# Copyright (C) 2010  Apple, Inc.
-# 
-# == Overview ==
-#
-# Grand Central Dispatch (GCD) is a novel approach to multicore computing
-# first released in Mac OS X version 10.6 Snow Leopard.
-# The Dispatch module and associated classes (Queue, Group, Semaphore, Source)
-# in MacRuby core provides a simple wrapping on top of the libdispatch C API.
-# This library provides higher-level services and convenience methods
-# to make it easier for traditional Ruby programmers to add multicore support.
-
-require 'dispatch/source'
-require 'dispatch/queue'
-require 'dispatch/proxy'
-require 'dispatch/job'
-require 'dispatch/enumerable'

Deleted: MacRuby/trunk/sample-macruby/Scripts/gcd/benchmarks.rb
===================================================================
--- MacRuby/trunk/sample-macruby/Scripts/gcd/benchmarks.rb	2010-12-08 00:26:31 UTC (rev 4993)
+++ MacRuby/trunk/sample-macruby/Scripts/gcd/benchmarks.rb	2010-12-08 02:35:02 UTC (rev 4994)
@@ -1,90 +0,0 @@
-#!/usr/local/bin/macruby
-#
-# Iterate using different GCD techniques to illustrate relative performance/overhead
-#
-# Inspired by: https://developer.apple.com/mac/library/samplecode/Dispatch_Compared/index.html
-
-require 'dispatch'
-require 'benchmark'
-
-$max_tasks = 256
-$reps = 1024
-$folds = 8
-$results = nil#[]
-
-$group = Dispatch::Group.new
-$queue = Dispatch::Queue.new('org.macruby.gcd.serial')
-
-class Benchmark
-  def self.repeat(count, label="", &block)
-    raise "count: #{count} < 1" if count < 1
-    block.call
-    t = measure {count.times &block} / count
-    Tms.new(*t.to_a[1..-1], label)
-  end
-end
-
-def work_function(i)
-    x = 1.0+i*i
-    $folds.times {|j| x = Math::tan(Math::PI/2 - Math::atan(Math::exp(2*Math::log(Math::sqrt(x))))) }
-    $results[i] = x if not $results.nil?
-end
-
-def times(n)
-  n.times {|i| work_function(i)}
-end
-
-def ptimes(n)
-  n.p_times {|i| work_function(i)}
-end
-
-def apply(n)
-  Dispatch::Queue.concurrent.apply(n) {|i| work_function(i)}
-end
-
-def concur(n)
-  q = Dispatch::Queue.concurrent
-  n.times do |i|
-    q.async($group) {work_function(i)}
-  end
-  $group.wait
-end
-
-def serial(n)
-  n.times {|i| $queue.async {work_function(i)}}
-  $queue.sync { } 
-end
-
-def nqueue(n)
-  n.times do |i|
-    Dispatch::Queue.new("org.macruby.gcd.multi.#{i}").async($group) {work_function(i)}
-  end
-  $group.wait
-end
-
-def njobs(n)
-  j = Dispatch::Job.new
-  n.times {|i| j.add { work_function(i) }}
-  j.join
-end
-
-def bench(method, count=1)
-  proc = Proc.new { send(method.to_sym, count) }
-  Benchmark.repeat($reps, "%6s" % method, &proc).real*1e6/count
-end
-
-METHODS = %w(times ptimes apply concur serial nqueue njobs)
-TASKS = [t = 1]
-TASKS << t *= 2 while t < $max_tasks
-
-print "GCD BENCHMARKS\tMaxTask\t#{$max_tasks}\tFolds\t#{$folds}\tReps\t#{$reps}\n"
-print "T µsec\t   #{TASKS.join("\t   ")}"
-
-METHODS.each do |method|
-  print "\n#{method}"
-  TASKS.each do |n|
-      print "\t%6.2f" % bench(method, n)
-   end
-end
-puts
-print "Results: #{$results.join("\t")}" if not $results.nil?

Deleted: MacRuby/trunk/sample-macruby/Scripts/gcd/dispatch_methods.rb
===================================================================
--- MacRuby/trunk/sample-macruby/Scripts/gcd/dispatch_methods.rb	2010-12-08 00:26:31 UTC (rev 4993)
+++ MacRuby/trunk/sample-macruby/Scripts/gcd/dispatch_methods.rb	2010-12-08 02:35:02 UTC (rev 4994)
@@ -1,277 +0,0 @@
-#!/usr/local/bin/macruby
-
-require 'dispatch'	
-job = Dispatch::Job.new { Math.sqrt(10**100) }
- at result = job.value
-puts "value (sync): #{@result} => 1.0e+50"
-
-job.value {|v| puts "value (async): #{v} => 1.0e+50" } # (eventually)
-job.join
-puts "join done (sync)"
-
-job.join { puts "join done (async)" }
-job.add { Math.sqrt(2**64) }
-job.value {|b| puts "value (async): #{b} => 4294967296.0" }
- at values = job.values
-puts "values: #{@values.inspect} => [1.0E50]"
-job.join
-puts "values: #{@values.inspect} => [1.0E50, 4294967296.0]"
-job = Dispatch::Job.new {}
- at hash = job.synchronize Hash.new
-puts "synchronize: #{@hash.class} => Dispatch::Proxy"
-
-puts "values: #{job.values.class} => Dispatch::Proxy"
-
- at hash[:foo] = :bar
-puts "proxy: #{@hash} => {:foo=>:bar}"
- at hash.delete :foo
-
-
-[64, 100].each do |n|
-	job.add { @hash[n] = Math.sqrt(10**n) }
-end
-job.join
-puts "proxy: #{@hash} => {64 => 1.0E32, 100 => 1.0E50}"
-
- at hash.inspect { |s| puts "inspect: #{s} => {64 => 1.0E32, 100 => 1.0E50}" }
-delegate = @hash.__value__
-puts "\n__value__: #{delegate.class} => Hash"
-
-n = 42
-job = Dispatch::Job.new { puts "n (during): #{n} => 42" }
-job.join
-
-n = 0
-job = Dispatch::Job.new { n = 21 }
-job.join
-puts "n (after): #{n} => 0?!?"
-n = 0
-job = Dispatch::Job.new { n += 84 }
-job.join
-puts "n (+=): #{n} => 0?!?"
-5.times { |i| print "#{10**i}\t" }
-puts "times"
-
-5.p_times { |i| print "#{10**i}\t" }
-puts "p_times"
-
-5.p_times(3) { |i| print "#{10**i}\t" }
-puts "p_times(3)"
-DAYS=%w(Mon Tue Wed Thu Fri)
-DAYS.each { |day| print "#{day}\t"}
-puts "each"
-DAYS.p_each { |day| print "#{day}\t"}
-puts "p_each"
-DAYS.p_each(3) { |day| print "#{day}\t"}
-puts "p_each(3)"
-DAYS.each_with_index { |day, i | print "#{i}:#{day}\t"}
-puts "each_with_index"
-DAYS.p_each_with_index { |day, i | print "#{i}:#{day}\t"}
-puts "p_each_with_index"
-DAYS.p_each_with_index(3) { |day, i | print "#{i}:#{day}\t"}
-puts "p_each_with_index(3)"
-print (0..4).map { |i| "#{10**i}\t" }.join
-puts "map"
-
-print (0..4).p_map { |i| "#{10**i}\t" }.join
-puts "p_map"
-print (0..4).p_map(3) { |i| "#{10**i}\t" }.join
-puts "p_map(3)"
-mr = (0..4).p_mapreduce(0) { |i| 10**i }
-puts "p_mapreduce: #{mr} => 11111"
-mr = (0..4).p_mapreduce([], :concat) { |i| [10**i] }
-puts "p_mapreduce(:concat): #{mr} => [1, 1000, 10, 100, 10000]"
-
-mr = (0..4).p_mapreduce([], :concat, 3) { |i| [10**i] }
-puts "p_mapreduce(3): #{mr} => [1000, 10000, 1, 10, 100]"
-puts "find_all | p_find_all | p_find_all(3)"
-puts (0..4).find_all { |i| i.odd? }.inspect
-puts (0..4).p_find_all { |i| i.odd? }.inspect
-puts (0..4).p_find_all(3) { |i| i.odd? }.inspect
-
-puts "find | p_find | p_find(3)"
-puts (0..4).find { |i| i == 5 }.nil? # => nil
-puts (0..4).p_find { |i| i == 5 }.nil? # => nil
-puts (0..4).p_find(3) { |i| i == 5 }.nil? # => nil
-puts "#{(0..4).find { |i| i.odd? }} => 1"
-puts "#{(0..4).p_find { |i| i.odd? }} => 1?"
-puts "#{(0..4).p_find(3) { |i| i.odd? }} => 3?"
-puts
-puts q = Dispatch::Queue.new("org.macruby.queue.example")
-q.sync { puts "queue sync" }
-
-q.async { puts "queue async" }
-	
-puts "queue join"
-q.join
-puts
-puts semaphore = Dispatch::Semaphore.new(0)
-q.async {
-	puts "semaphore signal"
-	semaphore.signal
-}
-
-puts "semaphore wait"
-semaphore.wait
-
-
-puts
-timer = Dispatch::Source.periodic(0.4) do |src|
- 	puts "Dispatch::Source.periodic: #{src.data}"
-end
-sleep 1 # => 1 1 ...
-
-timer.suspend!
-puts "suspend!"
-sleep 1
-timer.resume!
-puts "resume!"
-sleep 1 # => 1 2 1 ...
-timer.cancel!
-puts "cancel!"
-puts
- at sum = 0
-adder = Dispatch::Source.add do |s|
- 	puts "Dispatch::Source.add: #{s.data} (#{@sum += s.data})"
-	semaphore.signal
-end
-adder << 1
-semaphore.wait
-puts "sum: #{@sum} => 1"
-adder.suspend!
-adder << 3
-adder << 5
-puts "sum: #{@sum} => 1"
-adder.resume!
-semaphore.wait
-puts "sum: #{@sum} => 9"
-adder.cancel!
- at mask = 0
-masker = Dispatch::Source.or do |s|
-	@mask |= s.data
-	puts "Dispatch::Source.or: #{s.data.to_s(2)} (#{@mask.to_s(2)})"
-	semaphore.signal
-end
-masker << 0b0001
-semaphore.wait
-puts "mask: #{@mask.to_s(2)} => 1"
-masker.suspend!
-masker << 0b0011
-masker << 0b1010
-puts "mask: #{@mask.to_s(2)} => 1"
-masker.resume!
-semaphore.wait
-puts "mask: #{@mask.to_s(2)} => 1011"
-masker.cancel!
-puts
-
- at event = 0
-mask = Dispatch::Source::PROC_EXIT | Dispatch::Source::PROC_SIGNAL
-proc_src = Dispatch::Source.process($$, mask) do |s|
-	@event |= s.data
-	puts "Dispatch::Source.process: #{s.data.to_s(2)} (#{@event.to_s(2)})"
-	semaphore.signal
-end
-
-
-semaphore2 = Dispatch::Semaphore.new(0)
- at events = []
-mask2 = [:exit, :fork, :exec, :signal]
-proc_src2 = Dispatch::Source.process($$, mask2) do |s|
-	these = Dispatch::Source.data2events(s.data)
-	@events += these
-	puts "Dispatch::Source.process: #{these} (#{@events})"
-	semaphore2.signal
-end
-sig_usr1 = Signal.list["USR1"]
-Signal.trap(sig_usr1, "IGNORE")
-Process.kill(sig_usr1, $$)
-Signal.trap(sig_usr1, "DEFAULT")
-semaphore.wait
-result = @event & mask
-print "@event: #{result.to_s(2)} =>"
-puts  " #{Dispatch::Source::PROC_SIGNAL.to_s(2)} (Dispatch::Source::PROC_SIGNAL)"
-proc_src.cancel!
-semaphore2.wait
-puts "@events: #{(result2 = @events & mask2)} => [:signal]"
-proc_src2.cancel!
-puts "event2num: #{Dispatch::Source.event2num(result2[0]).to_s(2)} => #{result.to_s(2)}"
-puts "data2events: #{Dispatch::Source.data2events(result)} => #{result2}"
- at signals = 0
-sig_usr2 = Signal.list["USR2"]
-signal = Dispatch::Source.signal(sig_usr2) do |s|
-	puts "Dispatch::Source.signal: #{s.data} (#{@signals += s.data})"
-	semaphore.signal
-end
-puts "signals: #{@signals} => 0"
-signal.suspend!
-Signal.trap(sig_usr2, "IGNORE")
-3.times { Process.kill(sig_usr2, $$) }
-Signal.trap(sig_usr2, "DEFAULT")
-signal.resume!
-semaphore.wait
-puts "signals: #{@signals} => 3"
-signal.cancel!
-puts
- at fevent = 0
- at msg = "#{$$}-#{Time.now.to_s.gsub(' ','_')}"
-puts "msg: #{@msg}"
-filename = "/tmp/dispatch-#{@msg}"
-puts "filename: #{filename}"
-file = File.open(filename, "w")
-fmask = Dispatch::Source::VNODE_DELETE | Dispatch::Source::VNODE_WRITE
-file_src = Dispatch::Source.file(file.fileno, fmask, q) do |s|
-	@fevent |= s.data
-	puts "Dispatch::Source.file: #{s.data.to_s(2)} (#{@fevent.to_s(2)})"
-	semaphore.signal
-end
-file.print @msg
-file.flush
-file.close
-semaphore.wait(0.1)
-print "fevent: #{(@fevent & fmask).to_s(2)} =>"
-puts " #{Dispatch::Source::VNODE_WRITE.to_s(2)} (Dispatch::Source::VNODE_WRITE)"
-File.delete(filename)
-semaphore.wait(0.1)
-print "fevent: #{@fevent.to_s(2)} => #{fmask.to_s(2)}"
-puts " (Dispatch::Source::VNODE_DELETE | Dispatch::Source::VNODE_WRITE)"
-file_src.cancel!
-q.join
-
- at fevent2 = []
-file = File.open(filename, "w")
-fmask2 = %w(delete write)
-file_src2 = Dispatch::Source.file(file, fmask2) do |s|
-	@fevent2 += Dispatch::Source.data2events(s.data)
-	puts "Dispatch::Source.file: #{Dispatch::Source.data2events(s.data)} (#{@fevent2})"
-	semaphore2.signal
-end
-file.print @msg
-file.flush
-semaphore2.wait(0.1)
-puts "fevent2: #{@fevent2} => [:write]"
-file_src2.cancel!
-
-file = File.open(filename, "r")
- at input = ""
-reader = Dispatch::Source.read(file) do |s|
-	@input << file.read(s.data)
-	puts "Dispatch::Source.read: #{s.data}: #{@input}"
-end
-while (@input.size < @msg.size) do; end
-puts "input: #{@input} => #{@msg}" # => e.g., 74323-2010-07-07_15:23:10_-0700
-reader.cancel!
-file = File.open(filename, "w")
- at next_char = 0
-writer = Dispatch::Source.write(file) do |s|
-	if @next_char < @msg.size then
-		char = @msg[@next_char]
-		file.write(char)
-		@next_char += 1	
-		puts "Dispatch::Source.write: #{char}|#{@msg[@next_char..-1]}"
-	end
-end
-while (@next_char < @msg.size) do; end
-puts "output: #{File.read(filename)} => #{@msg}" # e.g., 74323-2010-07-07_15:23:10_-0700
-File.delete(filename)
-	

Deleted: MacRuby/trunk/sample-macruby/Scripts/gcd/dispatch_methods.sh
===================================================================
--- MacRuby/trunk/sample-macruby/Scripts/gcd/dispatch_methods.sh	2010-12-08 00:26:31 UTC (rev 4993)
+++ MacRuby/trunk/sample-macruby/Scripts/gcd/dispatch_methods.sh	2010-12-08 02:35:02 UTC (rev 4994)
@@ -1,5 +0,0 @@
-#!/bin/sh
-DISPATCH=../../../lib/dispatch
-/bin/echo -n "#!"
-which macruby
-grep "	" $DISPATCH/README.rdoc | sed "s/	//" | grep -v '\$ '

Deleted: MacRuby/trunk/sample-macruby/Scripts/gcd/ring_buffer.rb
===================================================================
--- MacRuby/trunk/sample-macruby/Scripts/gcd/ring_buffer.rb	2010-12-08 00:26:31 UTC (rev 4993)
+++ MacRuby/trunk/sample-macruby/Scripts/gcd/ring_buffer.rb	2010-12-08 02:35:02 UTC (rev 4994)
@@ -1,95 +0,0 @@
-#!/usr/local/bin/macruby
-# Ruby Fiber Ring Benchmark
-# Adapted for GCD from: http://people.equars.com/2008/5/22/ruby-fiber-ring-benchmark
-
-require 'benchmark'
-require 'dispatch'
-
-DEBUG = false
-
-START  = DEBUG ? 0 : 1
-N_NODES = DEBUG ? 1 : 4
-M_MESSAGES = DEBUG ? 0 : 3
-
-class Node
-    attr_accessor :successor
-    attr_reader :index
-    def initialize(g, index, successor)
-        @queue = Dispatch::Queue.for(self)
-        @group = g
-        @index = index
-        @successor = successor
-        @current = 0
-    end
-            
-    def call(m)
-        @queue.async(@group) do
-            case m
-            when 0
-                return
-            when @current
-                call(m-1)
-            else 
-                puts "\t#{self}.call(#{m})" if DEBUG
-                @current = m
-                @successor.call(m)
-            end
-        end
-    end
-    
-    def to_s
-        "##{@index}->#{@successor.index}[#{@current}]"
-    end
-end
-
-class Ring
-    def initialize(n)
-        @group = Dispatch::Group.new
-        @nodes = []
-        setup(n)
-    end
-    
-    def setup(n)
-        last = nil
-        n.downto(1) do |i|
-            @nodes << Node.new(@group, i, last)
-            last = @nodes[-1]
-        end
-        @nodes[0].successor = last
-    end
-    
-    def call(m)
-        @nodes[-1].call(m)
-        @group.wait
-    end
-    
-    def to_s
-        @nodes.reverse.join " | "
-    end
-end
-
-def bench(n,m)
-  tm  = Benchmark.measure {
-     yield
-  }.format("%8.6r\n").gsub!(/\(|\)/, "")
-
-  puts "#{n}, #{m}, #{tm}"
-  
-end
-
-START.upto N_NODES do |p|
-    n = 10**p
-    ring = Ring.new n
-    puts "\nRing of size #{n}:"
-    puts "\t#{ring}" if DEBUG
-    START.upto(M_MESSAGES) do |q|
-      r = 10**q
-      [r, 2*r, 5*r].each do |m|
-          puts "#{m} message(s)" if DEBUG
-        bench(n,m) { ring.call m }
-      end
-    end
-end
-
-        
-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101207/b8f6c597/attachment-0001.html>


More information about the macruby-changes mailing list