Created
September 12, 2013 19:00
-
-
Save thinkerbot/6542301 to your computer and use it in GitHub Desktop.
Processes blow away thread queues, for the record.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # time ./test/benchmark/psdaisy | |
| # | |
| # real 0m0.238s | |
| # user 0m0.095s | |
| # sys 0m0.006s | |
| # | |
| # real 0m0.323s | |
| # user 0m0.153s | |
| # sys 0m0.035s | |
| # | |
| mkdir example | |
| cd example | |
| ruby -e "('aa'..'dv').to_a.each {|name| puts name}" | xargs mkfifo | |
| ruby -e '100000.times {|i| puts i }' > aa & | |
| ruby -e "('aa'..'dv').to_a.inject(nil) {|a,b| puts '%s %s' % [a, b] if a; b }" | | |
| while read input output | |
| do cat "$input" > "$output" & | |
| done | |
| time cat dv > /dev/null | |
| cd - | |
| rm -r example |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'thread' | |
| queues = {} | |
| ('aa'..'dv').to_a.each do |name| | |
| queues[name] = Queue.new | |
| end | |
| threads = [] | |
| ('aa'..'dv').to_a.inject(nil) do |a,b| | |
| if a | |
| iqueue = queues[a] | |
| oqueue = queues[b] | |
| threads << Thread.new do | |
| while obj = iqueue.pop | |
| oqueue.push obj | |
| end | |
| end | |
| end | |
| b | |
| end | |
| src = Thread.new do | |
| iqueue = queues['aa'] | |
| 100000.times do |i| | |
| iqueue.push i | |
| end | |
| end | |
| oqueue = queues['dv'] | |
| while obj = oqueue.pop | |
| puts obj | |
| end | |
| threads << src | |
| threads.each {|thr| thr.join } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment