Skip to content

Instantly share code, notes, and snippets.

View tadd's full-sized avatar

Tadashi Saito tadd

View GitHub Profile
@tadd
tadd / memprof.rb
Created November 11, 2009 10:07
super-irresponsible memory profiler
def memprof
def vmsize
IO.readlines("/proc/self/status").grep(/VmSize/)[0].scan(/\d+/)[0].to_i
end
GC.start
GC.disable
before = vmsize
begin
yield
after = vmsize
.file "tmp.c"
.section .rodata
.LC0:
.string "hello world"
.text
.globl main
.type main, @function
main:
leal 4(%esp), %ecx
andl $-16, %esp
@tadd
tadd / ffsc.c
Created January 4, 2010 15:46
ffsc - far faster Scala compiler
/*
* ffsc - far faster scala compiler, omit booting time of fsc(1)
*
* Copyright (c) 2010 Tadashi Saito
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@tadd
tadd / benchmark-sin.rb
Created July 5, 2010 09:24
benchmark Decimal vs BigDecimal by sin()
require "decimal"
require "bigdecimal"
require "bigdecimal/math"
N = 100
STEP = 10
TRY = 10
result = {
n: (0..N).map{|m|m * STEP},
@tadd
tadd / benchmark-math.csv
Created July 12, 2010 15:24
Math functions benchmark, Decimal vs BigDecimal
sqrt Decimal BigDecimal
0 0 0
30 0.124887 0.028016
60 0.168286 0.050961
90 0.193021 0.089924
120 0.244228 0.120451
150 0.284446 0.152398
180 0.328916 0.18304
210 0.392945 0.316898
240 0.460614 0.386293
@tadd
tadd / functest.rb
Created July 30, 2010 13:56
Decimal::Math functions test
require "decimal"
y = Decimal::Math.sqrt(2, 50)
puts "sqrt(2) = #{y}" #=> sqrt(2) = 1.41421356237309504880168872420969807856967187537694
include Decimal::Math # you can include the module, same as ::Math
y = log(10, 50)
puts "log(10) = #{y}" #=> log(10) = 2.30258509299404568401799145468436420760110148862848
@tadd
tadd / bernoulli.patch
Created August 2, 2010 14:08
patch for ISBN4-87408-414-1 p.324
--- bernoull.c~ 1991-01-20 18:43:42.000000000 +0900
+++ bernoull.c 2010-08-02 23:06:40.000000000 +0900
@@ -21,6 +21,7 @@ int main()
int i, n;
double q, b1, b2, d;
static double t[N + 1];
+ int s = -1;
q = 1;
t[1] = 1;
(1996/4: 中学入学)
1998/10: 第二種情報処理技術者試験合格
(1999/4: 高校入学)
1999/8: www.linux.or.jp にて「オープンソースソフトウェア」ブックレビュー
http://www.linux.or.jp/bookreview/OpenSrcSoftware.html#issue3
(2002/4: 大学入学)
#include <iostream>
#include <cstdlib>
using namespace std;
int operacion(int x)
{
int y;
static const int primes[] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 79, 83, 89, 97
};
@tadd
tadd / csv-foreach-return-enumerator-if-no-block-given.diff
Created November 24, 2010 05:35
CSV.foreach: return Enumerator if no block given.
Index: lib/csv.rb
===================================================================
--- lib/csv.rb (revision 29897)
+++ lib/csv.rb (working copy)
@@ -1198,6 +1198,7 @@
encoding = options.delete(:encoding)
mode = "rb"
mode << ":#{encoding}" if encoding
+ return open(path, mode, options).to_enum if block.nil?
open(path, mode, options) do |csv|