Sha256: e6c18c280f9156d1de771e4ee67c7b9f59a168aefa7ec596a55d9677696c37bb
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
#!/usr/bin/env ruby require 'test/unit' require 'pmap' class Pmap_Test < Test::Unit::TestCase def bad_test_noproc_range range = (1..10) assert_equal(range.map, range.pmap) end def test_basic_range proc = Proc.new {|x| x*x} range = (1..10) assert_equal(range.map(&proc), range.pmap(&proc)) end def bad_test_noproc_array array = (1..10).to_a assert_equal(array.map, array.pmap) end def test_basic_array proc = Proc.new {|x| x*x*x} array = (1..10).to_a assert_equal(array.map(&proc), array.pmap(&proc)) end def test_time_savings start = Time.now (1..10).pmap{ sleep 1 } elapsed = Time.now-start assert(elapsed < 2, 'Parallel sleeps too slow: %.1f seconds' % elapsed) end def test_bad_thread_limits assert_raise(ArgumentError) {(1..10).pmap(-1){ sleep 1 }} assert_raise(ArgumentError) {(1..10).peach(0){ sleep 1 }} assert_raise(ArgumentError) {(1..10).peach(0.99){ sleep 1 }} assert_raise(ArgumentError) {(1..10).pmap('a'){ sleep 1 }} assert_raise(ArgumentError) {(1..10).peach([1,2,3]){ sleep 1 }} end def test_thread_limits start = Time.now (1..10).pmap(5){ sleep 1 } elapsed = Time.now-start assert(elapsed >= 2, 'Limited threads too fast: %.1f seconds' % elapsed) assert(elapsed < 3, 'Parallel sleeps too slow: %.1f seconds' % elapsed) end def test_defaut_thread_limit start = Time.now (1..128).pmap{ sleep 1 } elapsed = Time.now-start assert(elapsed >= 2, 'Limited threads too fast: %.1f seconds' % elapsed) assert(elapsed < 3, 'Parallel sleeps too slow: %.1f seconds' % elapsed) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pmap-0.0.2 | test/pmap_test.rb |