Skip to content

Instantly share code, notes, and snippets.

View huned's full-sized avatar
💭
I may be slow to respond.

Huned Botee huned

💭
I may be slow to respond.
View GitHub Profile
@huned
huned / complete_nary_tree.rb
Last active August 29, 2015 14:15
Generates a Complete N-ary Tree given parameters (height, degree) in dot format. Visualize with graphviz.
#!/usr/bin/env ruby
class CompleteNaryTreeGenerator
def self.generate_dot(height, degree)
puts 'digraph {'
# Convenience.
d = degree
h = height
i = 1
#!/usr/bin/env ruby
File.readlines('./tmp/5.log').each.with_index do |line, i|
matches = line.match(/\s+MOPED: \S+ (\w+)/i)
next if matches.nil?
op = matches.to_a.last.downcase
t = line.match(/\(([.0-9]+)ms\)$/i).to_a.last
puts "#{i},#{op},#{t}"
end
def rescue_retry(tries = 2, options = {}, &block)
raise ArgumentError, 'gimme a block' unless block_given?
begin
tries -= 1
yield
rescue => e
if tries > 0
sleep(options[:sleep]) if options[:sleep]
retry
2010-01-12
2010-01-13
2010-01-14
2010-01-15
2010-01-16
2010-01-19
2010-01-20
2010-01-21
2010-01-22
2010-01-23
@huned
huned / gist:89c44bcfd76f1add3b31
Created June 3, 2015 17:12
`inject(:+)` vs `each +=`
irb(main):003:0> require 'benchmark'
=> true
irb(main):004:0> numbers = nil
=> nil
irb(main):005:0> puts Benchmark.measure { numbers = 1_000_000.times.map {|i| i.to_f }; 1 }
1.110000 0.000000 1.110000 ( 0.448476)
=> nil
irb(main):006:0> numbers.length
=> 1000000
irb(main):007:0> puts Benchmark.measure { numbers.inject(:+) }
adaptive@ubuntu:/opt/adaptiveplanning/hypergraph$ HYPERGRAPH_THREADS=8 TESTS=5k bundle exec ruby -Itest -J-server -J-Xmx40g test/performance/hypergraph_performance_tpc_test.rb
uri:classloader:/jruby/kernel/kernel.rb:28: warning: unsupported exec option: close_others
Run options: --seed 15672
# Running:
### Load Tables
5k 933.160000 21.630000 954.790000 (804.721107)
require 'test_helper'
require 'benchmark'
class HypergraphPerformanceTest < Minitest::Test
include Hypergraph::TestHelper::Schema
include Hypergraph::TestHelper::Benchmarking
include Hypergraph::TestHelper::Profiling
def setup
suites = (ENV['TESTS'] || '').split
http://chart.apis.google.com/chart?cht=ls&chs=600x120&chds=300,9908&chxt=y&chxs=0,444444,10,1,l,ffffff&chxl=0:|300|5244|9908&chco=0a0a0a&chm=B,f8f8f8,0,0,0|o,0a0a0a,0,-1,8&chls=3&chma=4,4,4,4&chg=0,50&chd=t:6830,4377,1571,6426,9698,7701,7484,3640,6261,2748,1347,7579,3155,2489,3974,6107,4584,3834,7234,5031,2942,3518,9470,3225,6448,6330,8853,3173,9908,1391
/* fucking gist */
.gist .gist-syntax {
overflow-x: hidden !important;
}
.gist .gist-meta {
font-family: Verdana;
font-size: 8px !important;
}
// Make Zend Framework barf all over, causing php to bus error. Then go use rails.
$x = new Zend_Date(new Zend_Date());