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
| require 'benchmark/ips' | |
| require 'active_support/hash_with_indifferent_access' | |
| require 'active_support/core_ext/hash' | |
| begin | |
| @attributes = [{ 'id' => 1, 'name' => 'Julia', 'created_at' => Time.now }] * 1000 | |
| @mapping = { 'id' => 'user_id' } | |
| def sleep | |
| super 0.00000001 # typecasting simulation |
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
| class Array | |
| def sorted_insert!(value) | |
| min, max = 0, size | |
| while max > min | |
| middle = (min + max) / 2 | |
| if self[ middle ] > value | |
| max = middle | |
| else |
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
| def re(f = false) | |
| begin | |
| yield | |
| rescue => e | |
| p e.__id__ | |
| f ? raise(e) : raise | |
| end | |
| end | |
| e = StandardError.new |
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 | |
| class Input | |
| def initialize(name = 'input.txt', lines = rand(10..20)) | |
| File.open(name, 'w+') do |file| | |
| lines.times do |i| | |
| file.puts (0..i).map { rand(-50..50) }.join(' ') | |
| end | |
| end | |
| end |