Skip to content

Instantly share code, notes, and snippets.

View yorickpeterse's full-sized avatar

Yorick Peterse yorickpeterse

View GitHub Profile
@yorickpeterse
yorickpeterse / ruby-prof.patch
Created July 7, 2013 19:06
Patches to get ruby-prof working with MRI 1.9.3, taken from https://github.com/skaes/rvm-patchsets
diff --git a/gc.c b/gc.c
index 0f84e22..feb54f1 100644
--- a/gc.c
+++ b/gc.c
@@ -98,6 +98,15 @@ ruby_gc_params_t initial_params = {
#endif
};
+#ifndef HAVE_LONG_LONG
+#define LONG_LONG long
@yorickpeterse
yorickpeterse / fan-control.sh
Last active December 15, 2015 05:49
Poor man's fan control for Macbooks that run Linux.
#!/usr/bin/env bash
set -e
minimum=2000
medium=4500
maximum=6200
value=$minimum
Numbers indicate the amount of iterations in 5 seconds.
The C example was compiled using:
clang -Wall -Wextra -pedantic -O2 test.c -o test
Results:
C: 2272688181
LuaJIT 170557787 => ~13x slower
Calculating -------------------------------------
Array#[] 201.052k i/100ms
Array#at 194.228k i/100ms
-------------------------------------------------
Array#[] 11.090M (± 2.2%) i/s - 55.490M
Array#at 10.003M (± 1.3%) i/s - 50.111M
Comparison:
Array#[]: 11089538.6 i/s
Array#at: 10002944.7 i/s - 1.11x slower
require 'socket'
server = Socket.new(:INET, :DGRAM)
client = Socket.new(:INET, :DGRAM)
server.bind(Socket.sockaddr_in(0, '127.0.0.1'))
client.connect(Socket.sockaddr_in(server.connect_address.ip_port, '127.0.0.1'))
client.write('hello world how are you doing')
@yorickpeterse
yorickpeterse / bench_node.sh
Created March 14, 2014 19:32
Accurate proof that Ruby is closer to the bear metal than Node.js
#!/usr/bin/env bash
siege -c 10 -b -t 30s http://localhost:9393
function external-monitor -d 'Enable/disable external monitor'
if [ "$argv[1]" = "on" ]
echo 'Starting bumblebeed...'
sudo systemctl start bumblebeed
echo 'Enabling discrete GPU...'
echo ON | sudo tee /proc/acpi/bbswitch
Starting program: /home/yorickpeterse/Private/Projects/ruby/rubinius/bin/rbx ./bin/mspec spec/ruby/core/io/select_spec.rb
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff7f8d700 (LWP 7548)]
[New Thread 0x7ffff1086700 (LWP 7549)]
[New Thread 0x7ffff0c85700 (LWP 7550)]
[New Thread 0x7fffe3fff700 (LWP 7551)]
[New Thread 0x7ffff0484700 (LWP 7552)]
[Thread 0x7fffe3fff700 (LWP 7551) exited]
[Thread 0x7ffff0484700 (LWP 7552) exited]
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/yorickpeterse/.rubies/ruby-2.2.2/bin/ruby /tmp/sequel_test.rb
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff7ff7700 (LWP 21397)]
Preparing...
Starting threads...
[New Thread 0x7ffff3a9a700 (LWP 21399)]
[New Thread 0x7ffff3898700 (LWP 21400)]
/home/yorickpeterse/.gem/ruby/2.2.2/gems/sequel-4.26.0/lib/sequel/database/transactions.rb:165: [BUG] Segmentation fault at 0x00000000000014
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0020 p:0011 s:0078 e:000077 BLOCK /home/yorickpeterse/.gem/ruby/2.2.2/gems/sequel-4.26.0/lib/sequel/database/transactions.rb:165
c:0019 p:0006 s:0076 e:000075 METHOD /home/yorickpeterse/.gem/ruby/2.2.2/gems/sequel-4.26.0/lib/sequel/core.rb:312
c:0018 p:0013 s:0073 e:000072 METHOD /home/yorickpeterse/.gem/ruby/2.2.2/gems/sequel-4.26.0/lib/sequel/database/transactions.rb:165
c:0017 p:0009 s:0069 e:000068 METHOD /home/yorickpeterse/.gem/ruby/2.2.2/gems/sequel-4.26.0/lib/sequel/database/transactions.rb:193
c:0016 p:0011 s:0064 e:000063 BLOCK /home/yorickpeterse/.gem/ruby/2.2.2/gems/sequel-4.26.0/lib/sequel/database/transactions.rb:98
c:0015 p:0008 s:0060 e:000059 BLOCK /home/yorickpeterse/.gem/ruby/2.2.2/gems/sequel-4.26.0/lib/sequel/dat