Created
June 24, 2012 23:25
-
-
Save nevir/2985474 to your computer and use it in GitHub Desktop.
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
| ➜ foo git:(master) ./sequential.rb | |
| Finished in 1.293349 | |
| ➜ foo git:(master) ./sequential.py | |
| Finished in 2.837504 | |
| ➜ foo git:(master) ./threads.rb | |
| Finished in 1.272466 | |
| ➜ foo git:(master) ./threads.py | |
| Finished in 3.681996 |
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 python | |
| from time import time | |
| COUNT = 50000000 | |
| def countdown(n): | |
| while n > 0: | |
| n -= 1 | |
| start = time() | |
| countdown(50000000) | |
| print("Finished in %f" % (time() - start)) |
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 | |
| COUNT = 50000000 | |
| count = proc do |n| | |
| while n > 0 do | |
| n -= 1 | |
| end | |
| end | |
| start = Time.now | |
| count.call(COUNT) | |
| puts "Finished in #{Time.now - start}" |
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 python | |
| from threading import Thread | |
| from time import time | |
| COUNT = 50000000 | |
| def countdown(n): | |
| while n > 0: | |
| n -= 1 | |
| start = time() | |
| t1 = Thread(target=countdown, args=(COUNT // 2,)) | |
| t2 = Thread(target=countdown, args=(COUNT // 2,)) | |
| t1.start(); t2.start() | |
| t1.join(); t2.join() | |
| print("Finished in %f" % (time() - start)) |
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 | |
| COUNT = 50000000 | |
| count = proc do |n| | |
| while n > 0 do | |
| n -= 1 | |
| end | |
| end | |
| start = Time.now | |
| t1 = Thread.new { count.call(COUNT / 2) } | |
| t2 = Thread.new { count.call(COUNT / 2) } | |
| t1.join; t2.join | |
| puts "Finished in #{Time.now - start}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment