This file contains 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" | |
@callbacks = %w( | |
TimerFired | |
ConnectionData | |
ConnectionUnbound | |
ConnectionAccepted | |
ConnectionCompleted | |
LoopbreakSignalled | |
ConnectionNotifyReadable |
This file contains 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" | |
require 'bigdecimal' | |
class BigDecimal | |
# raggi after hint from apeiros (round 1) | |
def raggi_round(n = 15) | |
s = to_s('f')[0,n+1] | |
i = s.index('.') | |
dp = n - i | |
dp = 0 if dp < 0 |
This file contains 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
# The Question: Should this work? | |
# The Bonus Question: Does it, and in what capacity? | |
def parse_message(str) | |
last = nil | |
@parser ||= Parser.new { |message| last = message } | |
@parser << str | |
last | |
end |
This file contains 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' | |
def many | |
10000 | |
end | |
def push(left_array_size, right_array_size) | |
left = Array.new(left_array_size) { |n| n } | |
right = Array.new(right_array_size) { |n| n } | |
Benchmark.realtime{ many.times{ |i| left.push(*right) } } |
This file contains 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" | |
STRING = '1234567890' | |
FROZEN = STRING.dup.freeze | |
FROZEN_KEY = { | |
FROZEN => :something | |
} |
This file contains 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" | |
KEY = '1234567890' | |
HASH = { | |
KEY => KEY | |
} | |
TESTS = 2_000_000 |
This file contains 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 times_for_period(date) | |
regular_hours_by_week = Hash.new(0) | |
regular_hours = 0 | |
other_hours = Hash.new(0) | |
work_days_for_period(date).each do |d| | |
times = d.times | |
regular_hours += times[:regular_hours] |
This file contains 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 | |
domain, room, *message = ARGV | |
token = File.read(ENV['HOME'] + '/.talker').strip | |
abort <<-TEXT unless domain && room && token | |
Usage: #{File.basename($0)} domain room_id [message] | |
Reads from stdin if no message supplied | |
Expects a user token in $HOME/.talker | |
TEXT |
This file contains 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
# This bug seems to occur on 1.8.6..1.9 on OSX and FreeBSD. It's known not to occur on Linux. | |
require 'rubygems' | |
require 'minitest/unit' | |
include MiniTest::Assertions | |
require 'tempfile' | |
path = nil | |
begin |
This file contains 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" | |
arr = [1,2,3,4,5,6,7,8,9,0] * 100 | |
GC.start | |
TESTS = 10_000 | |
Benchmark.bmbm do |results| | |
results.report("map:") { TESTS.times { arr.map { |i| i } } } | |
results.report("inj:") { TESTS.times { a = []; arr.inject(a, :<<) } } | |
end |