If you’re writing production code in Ruby and haven’t been exposed to optimization strategies, take a look at this tutorial. Learn how to profile and optimize Ruby code (free reg. req.) with RubyInline and ZenOptimize, two tools that make this process easier.
A good article, especially for beginners like myself. Having written (or tried to write) several benchmarks for the Computer Language Shootout, I have already run into some of the general tools – ‘time’ and the profiler, but not the benchmarking library. I had also not tried inlining C.
The article discusses general optimization strategy, but also gives some good hints for speedups, like using “print” and using for i in range instead of Fixnum#upto.
A few optimizational bits I have noticed, that are not mentioned in the article:
Using Lisp-style returns via function return values is faster than using the return statement, at least in simple cases. So, “def square(x); x * x; end” is faster than “def square(x); return x * x; end”.
Also, for whatever reason, attr_reader and attr_accessor produce faster accessor code than writing equivalent functions manually, even if the manual function is returning a constant. Weird!
http://bugmenot.com/view.php?url=www14.software.ibm.com
Ruby is a dying child
> Ruby is a dying child
Goodone, i was laughing my guts off man. Who are you? We should meet, i’d love to drink beer with a funny guy like you…
Somethings are praised best by a broad understatement that not all can understand. Ruby should be (and is) nutured by the ppl that know what it is capable of. Shouting around how good it is only messes up the userbase/community with n00bs. No, Ruby is one of the best kept sercrets of the internet and me and mister Anonymous (172.162.228.—) like it that way.
Cheers,
Cies Breijs.
try reading a lot of trolls about ruby, and never give it a good try! STAY AWAY FROM RUBY!
[hahahaa… (i have a really good time here)]
“Ruby is one of the best kept sercrets of the internet”
And here I thought I saw an OSNews or Slashdot article about it practically every day!
Despite that, Python still dwarfs it in popularity. Thankfully Rails is starting to change this…
There are so many of them.
Python,ruby,perl,php etc.
Each requires their own 30MB+ interpreter.
The interpreter should, if many application use it, offer a size advantage over non-scripted programs.
But with so many scripting languages it’s likely that the language that the developer likes it not one that I already have an interpreter for.
Therefore to get a program that does a fairly simple job requires a 30MB download.
The Python and Ruby interpreters aren’t that different.
Each requires their own 30MB+ interpreter.
Python’s interpreter download is around 10 megs. That’s a bit better than the JRE at 15 megs, far slimmer than the SDK at 53 megs, and thin compared to .NET at 24 megs.
The interpreter should, if many application use it, offer a size advantage over non-scripted programs.
Indeed. With one Python installation with a bit of wx thrown in on the side, I’m running around a dozen programs, includings a few that I wrote myself. Dividing all of their space equally, it comes down to around 2 megs per application, including GUI (and those are just the ones running right now).
The Python and Ruby interpreters aren’t that different.
Except that they are quite different. Please stop trolling.
Actually, you can get it down to ~2 mb by using py2exe for windows. Most other OS’s/linux distros I’ve seen include python anyway, so for them it’s even smaller.
-bytecoder
That’s why you should just use Perl.
I enjoyed this article very much.
I just recently decided to give Ruby a try (mainly experimenting with Rails). While there are some things in its syntax that I don’t like I think overall it is a great language.
I like scripting languages in general. Python and now Ruby being the two I like to use most. The thing that makes them stand out above compiled languages like C and C++, and even pseudo-compiled languages like Java and any of the .NET clones, is that I can get a lot more done in a lot less time.
I started with it recently as we are very likely to base a lot of future development on it, and we all like it here. I’ve been sorta following it for at least 2 years but never bothered to get into it. I should have done so!
download sizes don’t necessarily reflect memory usage, and harddisk sizes are super huge these days so HD usages of 10-30mb are nothing. Maybe if I was stuck on the 80mb drive my amiga used, it’d be a point. However, ever since I had a 1gb drive in my amiga the harddisk’s of that and all future machines had exceeded my requirements. Only media(video & music) & games make ever bigger ones useful to me now. My current pc has 3 OSs on it and a home partition, and I still have unused space on my 200gig of storage as a lot of my media is fairly well organised on dvds & cds for portability.
Dunno what libraries are by default included with Python, Ruby, Perl etc., but as for interpreter size – Rebol/Core is some 250KB, and Rebol/View is some 650KB, newly including integrated AGG library for vectors. For most simple Internet related scripting stuff you don’t need anything else with REBOL.
Pretty compact for cross-platform scripting tool imo.
-pekr-
rebol really deserves more spotlight because it is truly an amazing tool. I did some smaller database apps using rebol mysql driver (itself built with rebol) and results are very good.
The python interpreter is 10 megs.
The .Net SDK is 106.
Does 10 megs really seem that bad now?
Ruby…
The Good: Very clean syntax. Best object grammar around. Everything truly is an object. Once you learn to think in ruby, you can code for hours and hours with few or no syntax errors. It’s great.
The Bad: Slower pace of development and fewer tools than Python. Python has language genius Jim Hugunin, developer of IronPython. If you don’t want to give away your sourcecode, in python you can distribute the bytecode, whereas that is not an option (AFAIK) with ruby.
The Ugly: Ruby is the most un-ugly programming language I’ve seen, period. I’d love it if someone would but a ruby front-end on a python interpreter so I could code in ruby and generate python bytecode. Ahhh…. heaven! Any takers??
Just look at YARV (it will be called rite.. it will be ready in 2006). I’m really looking forward to ruby 2.0
it will have native threads support that many people want. But my favourite new language feature is keyword arguments/hash literals.. I have too many :length=>5, :repeat=>12… like things in my code, length: 5, repeat: 12 will be much nicer.
Ruby 2.0 features:
http://www.rubygarden.org/ruby?Rite
YARV devel archives:
http://rubyforge.org/pipermail/yarv-devel/
Rebol may be small but, but commercial “[Purchase]” and very little open source in it.
I’m more of a Lua man myself.
Ah, once again open-source arguments? I always thought that the tool is either good enough to fullfill your job, or it is not. With REBOL, you can do many things not requiring commerical license, the basis is free. Commercial version sports some features, which are reimplemented by community as free scripts of course, so ๐
REBOL still waits for it to be praised a bit more, and I know it will be – sooner or later. It is very cool tool, which can do so much, in so little size. It has very strong expressive power. Just try to download View 1.3, go to Desktop, try some demos at rebol.com and right-clicking at script source, watch how actually “long” the script is – you may be surprised ๐
Thanks for pointing out Lua, will look at what it is about.
-pekr-
“Ah, once again open-source arguments?”, not really it is more about the $99 for DLL access… I like my DLL:s…
But I’ll check out the scripts…