Skip to content

Instantly share code, notes, and snippets.

@ferrous26
ferrous26 / test.java
Last active August 29, 2015 13:57
Java silliness
public class test {
public test() {
int[] a = new int['☃'];
a[1] = a[0];
}
}
### Keybase proof
I hereby claim:
* I am ferrous26 on github.
* I am ferrous26 (https://keybase.io/ferrous26) on keybase.
* I have a public key whose fingerprint is 1D34 82B6 1EB5 286D 8D61 E84C 1EE8 F634 208C EB3B
To claim this, I am signing this object:
require 'benchmark'
array_iterate = (1..10_000_000).to_a
array_shift = array_iterate.dup
Benchmark.bmbm do |test|
# this assumes you can destroy the given array
test.report 'using shift' do
for i in array_shift
@ferrous26
ferrous26 / if_unless.rb
Created February 5, 2011 22:23
Benchmarking if not vs unless
require 'benchmark'
n = 10_000_000
Benchmark.bmbm do |test|
test.report 'if not' do
n.times do
if not 0.nil?
0
end
@ferrous26
ferrous26 / shift-vs-offset.rb
Created February 6, 2011 06:35
Benchmarking shifting through an array versus calculating an offset when you need i to be i bet get at position i-1
require 'benchmark'
array_iterate = (1..10_000_000).to_a
array_shift = array_iterate.dup
Benchmark.bmbm do |test|
# this assumes you can destroy the given array
test.report 'using shift' do
for i in array_shift
@ferrous26
ferrous26 / bench_array_split_methods.rb
Created February 14, 2011 03:42
Testing if it is faster to split an array by dup/shift/splat or index/index/splat
require 'rubygems'
gem 'minitest'
require 'minitest/autorun'
require 'minitest/benchmark'
class Bench < MiniTest::Unit::TestCase
def self.test_order
:alpha
end
@ferrous26
ferrous26 / macruby-compile-tasks.rb
Created March 24, 2011 02:12
compile/clean tasks that can be dropped into rakefile for compile speed comparisons
require 'rake/compiletask'
Rake::CompileTask.new(:fast_compile) do |t|
t.files = FileList["lib/**/*.rb"]
t.verbose = true
end
desc 'AOT compile source files'
task :slow_compile do
start_time = Time.now
FileList["lib/**/*.rb"].each do |source|
@ferrous26
ferrous26 / implicit-vs-explicit blocks
Created March 26, 2011 18:08
implicit blocks with yield are 5x faster than explicit blocks
require 'benchmark'
n = 100_000
Benchmark.bmbm do |test|
test.report 'implicit block with yield' do
def test
yield if block_given?
end
n.times do test {} end
@ferrous26
ferrous26 / test.rb
Created May 19, 2011 05:41
Problem in MacRuby somewhere...but where?
require 'json'
require 'rubygems'
require 'restclient'
# setup db
DB = 'http://127.0.0.1:5984/test'
RestClient.delete DB rescue nil
RestClient.put DB, {}.to_json
# setup a document
@ferrous26
ferrous26 / compilation.markdown
Created May 26, 2011 05:09
Stdlib compilation times

2009 MBP (2.66 GHz C2D)

  • jobs=1 (7 minutes 32 seconds)

  • jobs=2 (4 minutes 31 seconds)

  • jobs=4 (4 minutes 20 seconds)

  • new (2 minutes 7 seconds)