Created
February 28, 2014 22:58
-
-
Save nilbus/9281785 to your computer and use it in GitHub Desktop.
Multiply Arrays runs out of memory with board dimension 1,000,000
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
| user system total real | |
| Loop and shovel 14.310000 0.200000 14.510000 ( 14.793983) | |
| Multiply arrays 7.220000 0.350000 7.570000 ( 7.854261) |
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 'benchmark' | |
| rows = 10000 | |
| columns = 10000 | |
| mines = 10000 | |
| Benchmark.bm do |bm| | |
| bm.report('Loop and shovel') { [].tap { |board| (columns * rows).times { |i| board << (i < mines ? 1 : 0) } }.shuffle! } | |
| bm.report('Multiply arrays') { ([1] * mines + [0] * (columns * rows - mines)).shuffle! } | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment