Skip to content

Instantly share code, notes, and snippets.

@pmahoney
pmahoney / Dockerfile
Last active August 14, 2019 18:30
kidn - k3s in dockerd's namespaces
FROM busybox:1.31.0
ENTRYPOINT ["echo", "it worked"]
@pmahoney
pmahoney / become_java_test.rb
Last active March 15, 2023 00:45
Test of become_java! and having java code call a ruby object.
require 'jruby/core_ext'
class MyObserver
include Java::JavaUtil::Observer
def update(observable, arg)
puts "UPDATE! #{observable}"
end
end
MyObserver.become_java! false
require 'bundler'
# First attempt a bundle install without remote resolution. In the
# happy case, all gems are already installed, and checking this is
# quick. If it fails, attempt a remote resolution. This is slow
# (probably largely because of how many dang gem versions we have in
# our local gem server), but it will install anything that is missing.
#
# Bundler uses lots of class-level configuration, and thus isn't
# designed to be called repeatedly with different options, but we're
require 'benchmark'
A = 'a'
B = 'b'
C = 'c'
D = 'd'
E = 'e'
F = 'f'
G = 'g'
H = 'h'
@pmahoney
pmahoney / benchmarks
Created December 7, 2012 16:55
Assets precompilation benchmark
See https://github.com/pmahoney/assets_comp_perf
rails 3.2.9, hike 1.2.1, sprockets 2.2.2
* denotes best time
Ruby 1.9.3-p194
$ time bundle exec rake assets:clean assets:precompile
@pmahoney
pmahoney / comments
Created November 1, 2012 21:30
JRuby $LOAD_PATH index speeds up Bundler.require in a Rails app (at top of application.rb)
Rails 3.1.8 app in Ruby 1.8 compatibility mode with ~65 dependencies
(not sure how many in total including
transient deps) was timed up to the Bundler.require line in config/application.rb
(JRuby 1.7.0)
Before: 18.8 seconds
After: 15.9 seconds
This likely seriously breaks the semantics of 'require', and maybe isn't faster
enough to be worth it.
this SunJCE_y (id=144)
arg0 true
arg1 "DESede/CBC/PKCS5Padding" (id=249)
arg2 (id=254)
@pmahoney
pmahoney / Time.java
Created October 18, 2012 17:29
RubyTime opPlusNanos maybe
public class Time {
private final long timeInMillis;
private final long nsec;
public Time(long timeInMillis, long nsec) {
this.timeInMillis = timeInMillis;
this.nsec = nsec;
}
@pmahoney
pmahoney / executor.rb
Created October 3, 2012 20:50
executors in jruby example
require 'java'
class Task
include Java::JavaUtilConcurrent::Callable
def initialize(num)
@num = num
end
def call
@pmahoney
pmahoney / results
Created September 13, 2012 15:50
Crummy kind_of? or respond_to? benchmark under JRuby
require 'java'
require 'benchmark'
s = Java::JavaLang::String.new('hello')
n = 10000000
respond_task = proc { n.times { s.respond_to?(:to_s) || abort('error') } }
no_respond_task = proc { n.times { s.respond_to?(:no_method) && abort('error') } }
kind_of_task = proc { n.times { s.kind_of?(Java::JavaLang::String) || abort('error') } }
no_kind_of_task = proc { n.times { s.kind_of?(Java::JavaLang::Integer) && abort('error') } }