I wrote something in ruby. Ruby has threads, but mysteriously lacks timers. So I wrote a dinky Timer class. I first called it Reminders, and that still might be a better name.
Bill W has written 3 entries about this goal
Still haven’t really hit the juicy stuff yet.
Q: isn’t this a problem?
a=”a string”
n=1
a=n
I mean, wouldn’t it be nice if that were a syntax error?
ruby looks promising. i downloaded rails this morning and liked what i saw.
i just noticed the comparison programs that come with the distribution, and i’d heard that one drawback to ruby is its performance, so i condcted a little benchmarking experiment. i chose the fib program, and i wrote the same thing in c and java to make the comparison more complete.
the results surprised me. (min:sec.hundredths)
| fib.c | 0.73 elapsed |
| fib.java | 22.61 elapsed |
| fib.rb | 1:08.00 elapsed |
| fib.pl | 1:37.66 elapsed |
fib.c:
| #include |
| size_t fib(size_t n) { |
| if(n<2) return n; |
| else return fib(n-2)+fib(n-1); |
| } |
| int main() { |
| printf(“%d\n”, fib(35)); |
| exit(0); |
| } |
| $ gcc -g -O fib.c -o fib |
| $ time ./fib |
| 9227465 |
| 0.73user 0.00system 0:00.73elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k |
| 0inputs+0outputs (0major+94minor)pagefaults 0swaps |
fib.java:
| class Fib { |
| public static int fib(int n) { |
| if(n<2) { |
| return n; |
| } else { |
| return fib(n-2)+fib(n-1); |
| } |
| } |
| public static void main(String[] args) { |
| System.out.println(fib(35)); |
| } |
| } |
| $ javac fib.java |
| $ time java Fib |
| 9227465 |
| 22.44user 0.07system 0:22.61elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k |
| 0inputs+0outputs (0major+4567minor)pagefaults 0swaps |
fib.rb:
| # calculate Fibonacci(20) |
| # for benchmark |
| def fib(n) |
| if n<2 |
| n |
| else |
| fib(n-2)+fib(n-1) |
| end |
| end |
| print(fib(35), ”\n”); |
| $ time ruby ./fib.rb |
| 9227465 |
| 67.37user 0.14system 1:08.00elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k |
| 0inputs+0outputs (0major+399minor)pagefaults 0swaps |
| fib.pl: |
| sub fib { |
| my($n)=@_; |
| if ($n<2) { |
| return $n; |
| } |
| else { |
| return fib($n-2)+fib($n-1); |
| } |
| } |
| print fib(35), ”\n”; |
| $ time perl ./fib.pl |
| 9227465 |
| 96.69user 0.22system 1:37.66elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k |
| 0inputs+0outputs (0major+412minor)pagefaults 0swaps |
Bill W has gotten 8 cheers on this goal.
AJBehrens cheered this 2 years ago
guyrso cheered this 2 years ago
IndianGuru cheered this 2 years ago
lordloki cheered this 2 years ago
Deirdre Saoirse Moen cheered this 4 years ago
Chad Fowler cheered this 4 years ago
danielmcg cheered this 4 years ago
pate cheered this 4 years ago
