Ruby - is it worth the effort?

Hello,

I've been browsing web few last days, researching ruby vs. stuff, but I can't come to conclusion.

I like the language itself and its freedom, but is it worth using it for desktop applications or simple games?

Seems like it is bit slow, but it does its job. I love the module system. For me it seems like a perfect compromise between C++ 'ish multi-inheritance and C# 'ish Interface system, which in my opinion just doubles the code. Arrays and strings are just wonderfull. It solves many things which were giving me headache in languages like C++.

Some people prefer python more, but it kinda comes down to personal preference, as they just like the python-way better.

What are your thoughts on Ruby?
Have you been using it in some bigger projects?

imo you could do everything possible in python in ruby too

about the speed, pure ruby code maybe slow but you can powerup it with
C-exts like in python

with the right bindings you could make desktop applications for GTK or
for QT (or use wxwidgets)

you could make 2D Games and also 3D games

for both kind (applications and Games) i currently make new ruby
bindings, but they are not finish yet

···

--
Posted via http://www.ruby-forum.com/.

Search existing games - have a look at what languages they are using.
GAming libraries exist for python, so probably for ruby as well.

Depending on your game you may want to start from scratch, or even use
cross platform libraries such as haxenme.org (THere are more like
this).

Which one is the right choice? Depends on your skills, your energy, your
goals, your time, ... hard choice.

Marc Weber

What are your thoughts on Ruby?

I find very fun making games with gosu-ruby. It's a framework to build
games with Ruby. Make the tutorial, meaby will catch you.
http://www.libgosu.org/

Ruby is not faster than C(obvious) but it's improving the speed through
time. For example in February 2013 will be released Ruby 2.0, which
seems to be faster than the actual 1.9.3. And is head to head(based on
an article that I read, don't remember the link) with languages like
Phyton.

Have you been using it in some bigger projects?

Actually I'm working on one of those, I'll tell what's happened when be
done.

···

--
Posted via http://www.ruby-forum.com/\.

Unfortunately with Ruby for me it's typically "fun and fast development"
but when you get to your end releasable, suddenly...it seems a bit too
slow cpu-wise. 100ms to service a rails request that does "not much"?
My specs take *how* long to run the full test suite? What? So
development is great, end result...tends to be slow.

C-ext's I guess could fix this...I've never tried it.

That being said, I use Ruby successfully for my GUI projects and, as
long as its' wrapping some other program in C to "do the heavy lifting"
then it's ok (except for jruby's startup times, but that's unrelated,
and not too bad).

So basically if you're ok with a "somewhat slow" end product, Ruby is
still grand, because programming in it is funner.

HTH.
-roger-

···

--
Posted via http://www.ruby-forum.com/.

"Some people prefer python more, but it kinda comes down to personal
preference, as they just like the python-way better."

Python seems a good choice.

I myself decided to use Ruby because of matz and the philosophies.

I try to find beauty in my code.

I left PHP because it was horribly inconsistent. There was nothing
beautiful about it.

"What are your thoughts on Ruby?"

Ruby is a very good language. I say about 80-90% perfection.

For my taste, it is a bit too complex, and some things like module vs.
class distinction don't make that much sense to me.

But I am ok with those drawbacks.

The speed to python is comparable.

If you however feel that ruby is too slow, the same applies for python
and perl. So then, use C. Not a scripting language if speed bites your
butt.

"Have you been using it in some bigger projects?"

Yes. In big projects, other problems come up.

For instance, documentation. I dont like rdoc at all.

Also some ruby projects tend to become complicated, like rails.

I try to make everything as simple as possible, whenever possible.

···

--
Posted via http://www.ruby-forum.com/.

It's all good and well that it can, yet about its effective and efficiency?
Some languages are also more proficient at such tasks.

···

On Mon, Sep 17, 2012 at 7:45 PM, Hans Mackowiak <lists@ruby-forum.com>wrote:

imo you could do everything possible in python in ruby too

about the speed, pure ruby code maybe slow but you can powerup it with
C-exts like in python

with the right bindings you could make desktop applications for GTK or
for QT (or use wxwidgets)

you could make 2D Games and also 3D games

for both kind (applications and Games) i currently make new ruby
bindings, but they are not finish yet

--
Posted via http://www.ruby-forum.com/\.

Roger Pack писал 17.09.2012 22:06:

So basically if you're ok with a "somewhat slow" end product, Ruby is
still grand, because programming in it is funner.

I want to note that there isn't a general measure for slowness. Is it
fast to crank 100MB of data in 1s? 10s? 1h? The answer doesn't depend
on the kind of data, or your programming language, or whatever. If the
application's behavior is within your (business) requirements, it's fast.
And most often the requirement isn't "response time under 10ms" (through
such applications definitely do exist), but the "lowest TCO", and hardware
scales way better than humans.

That being said, I won't write number crunching algorithms in Ruby, or work
with gigabyte-sized datasets.

···

--
   WBR, Peter Zotov.

That's got little to do with Ruby and a lot with the bloated, overkill
for most uses beast that is Rails.

For smaller projects, use smaller frameworks. Sinatra and Camping are fun.

-- Matma Rex

···

2012/9/17 Roger Pack <lists@ruby-forum.com>:

Unfortunately with Ruby for me it's typically "fun and fast development"
but when you get to your end releasable, suddenly...it seems a bit too
slow cpu-wise. 100ms to service a rails request that does "not much"?
My specs take *how* long to run the full test suite? What? So
development is great, end result...tends to be slow.

Roger Pack писал 17.09.2012 22:06:

So basically if you're ok with a "somewhat slow" end product, Ruby is
still grand, because programming in it is funner.

I want to note that there isn't a general measure for slowness. Is it
fast to crank 100MB of data in 1s? 10s? 1h? The answer doesn't depend
on the kind of data, or your programming language, or whatever. If the
application's behavior is within your (business) requirements, it's fast.

Right. Unfortunately too often these types of requirements are
forgotten... :slight_smile: Still it doesn't make your statement wrong - it's
just an additional data point. :wink:

And most often the requirement isn't "response time under 10ms" (through
such applications definitely do exist), but the "lowest TCO", and hardware
scales way better than humans.

Last weekend I attended a presentation of someone owning a company
which sells support for an open source software which it also
maintains. The software is a web application and someone asked about
scalability (how many users?). The guy said something like "It's a
web application. Look at facebook, that scales to several hundred
million users." - now, _that's_ marketing chuzpe.

That being said, I won't write number crunching algorithms in Ruby, or work
with gigabyte-sized datasets.

Well, even that depends. Sifting through logfiles of that volume is
almost certainly IO bound and the processing speed can be negligible.
That of course depends on the processing.

Kind regards

robert

···

On Mon, Sep 17, 2012 at 8:20 PM, Peter Zotov <whitequark@whitequark.org> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Being a Ruby shop we try to use Ruby everywhere but when it does come
to grinding through logfiles (some several gigs in size) we had to go
with Perl. The string processing and regex matching was so much
faster. We couldn't get Ruby even close :frowning: Speed was essential, we
couldn't just sit around and wait for the process to complete.

Right tools for the job I guess. Ruby is fine for everything else so
switching it all over to Perl would not really gain us anything.
Besides if you are a programmer knowing more than one language is a
must.

···

On 19 September 2012 09:24, Robert Klemme <shortcutter@googlemail.com> wrote:

On Mon, Sep 17, 2012 at 8:20 PM, Peter Zotov <whitequark@whitequark.org> wrote:

That being said, I won't write number crunching algorithms in Ruby, or work
with gigabyte-sized datasets.

Well, even that depends. Sifting through logfiles of that volume is
almost certainly IO bound and the processing speed can be negligible.
That of course depends on the processing.

That's what it comes down to ... right tool for right job.

···

On Wed, Sep 19, 2012 at 4:36 PM, Peter Hickman < peterhickman386@googlemail.com> wrote:

On 19 September 2012 09:24, Robert Klemme <shortcutter@googlemail.com> > wrote:
> On Mon, Sep 17, 2012 at 8:20 PM, Peter Zotov <whitequark@whitequark.org> > wrote:
>> That being said, I won't write number crunching algorithms in Ruby, or
work
>> with gigabyte-sized datasets.
>
> Well, even that depends. Sifting through logfiles of that volume is
> almost certainly IO bound and the processing speed can be negligible.
> That of course depends on the processing.

Being a Ruby shop we try to use Ruby everywhere but when it does come
to grinding through logfiles (some several gigs in size) we had to go
with Perl. The string processing and regex matching was so much
faster. We couldn't get Ruby even close :frowning: Speed was essential, we
couldn't just sit around and wait for the process to complete.

Right tools for the job I guess. Ruby is fine for everything else so
switching it all over to Perl would not really gain us anything.
Besides if you are a programmer knowing more than one language is a
must.

That being said, I won't write number crunching algorithms in Ruby, or work
with gigabyte-sized datasets.

Well, even that depends. Sifting through logfiles of that volume is
almost certainly IO bound and the processing speed can be negligible.
That of course depends on the processing.

Being a Ruby shop we try to use Ruby everywhere but when it does come
to grinding through logfiles (some several gigs in size) we had to go
with Perl. The string processing and regex matching was so much
faster. We couldn't get Ruby even close :frowning: Speed was essential, we
couldn't just sit around and wait for the process to complete.

Was that 1.8.* or did you try that with 1.9.* MRI? What kind of
processing did you do and how big were the differences?

Right tools for the job I guess. Ruby is fine for everything else so
switching it all over to Perl would not really gain us anything.
Besides if you are a programmer knowing more than one language is a
must.

+1

Cheers

robert

···

On Wed, Sep 19, 2012 at 10:36 AM, Peter Hickman <peterhickman386@googlemail.com> wrote:

On 19 September 2012 09:24, Robert Klemme <shortcutter@googlemail.com> wrote:

On Mon, Sep 17, 2012 at 8:20 PM, Peter Zotov <whitequark@whitequark.org> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Being a Ruby shop we try to use Ruby everywhere but when it does come
to grinding through logfiles (some several gigs in size) we had to go
with Perl. The string processing and regex matching was so much
faster. We couldn't get Ruby even close :frowning: Speed was essential, we
couldn't just sit around and wait for the process to complete.

might be useful, if it ends up being regex's that are the slowdown :slight_smile:
-r

···

--
Posted via http://www.ruby-forum.com/\.

Was that 1.8.* or did you try that with 1.9.* MRI? What kind of
processing did you do and how big were the differences?

I'd like to know, too. I stumbled upon a similar problem, but it was long
ago.

···

2012/9/19 Robert Klemme <shortcutter@googlemail.com>

On Wed, Sep 19, 2012 at 10:36 AM, Peter Hickman > <peterhickman386@googlemail.com> wrote:
> On 19 September 2012 09:24, Robert Klemme <shortcutter@googlemail.com> > wrote:
>> On Mon, Sep 17, 2012 at 8:20 PM, Peter Zotov <whitequark@whitequark.org> > wrote:
>>> That being said, I won't write number crunching algorithms in Ruby, or
work
>>> with gigabyte-sized datasets.
>>
>> Well, even that depends. Sifting through logfiles of that volume is
>> almost certainly IO bound and the processing speed can be negligible.
>> That of course depends on the processing.
>
> Being a Ruby shop we try to use Ruby everywhere but when it does come
> to grinding through logfiles (some several gigs in size) we had to go
> with Perl. The string processing and regex matching was so much
> faster. We couldn't get Ruby even close :frowning: Speed was essential, we
> couldn't just sit around and wait for the process to complete.

Was that 1.8.* or did you try that with 1.9.* MRI? What kind of
processing did you do and how big were the differences?

> Right tools for the job I guess. Ruby is fine for everything else so
> switching it all over to Perl would not really gain us anything.
> Besides if you are a programmer knowing more than one language is a
> must.

+1

Cheers

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

--
Carlos Agarie
Control engineering student
Polytechnic School
University of São Paulo

Interesting. Thank you for the pointer! Too bad it does not support
encodings which is probably a show stopper for inclusion in the core
lib. At least as standard regexp engine it's not usable. Apparently
boost regexp's support Unicode but I guess adjustment need some effort
- and then the question is whether performance gains are still so big.

Kind regards

robert

···

On Wed, Sep 19, 2012 at 2:40 PM, Roger Pack <lists@ruby-forum.com> wrote:

Being a Ruby shop we try to use Ruby everywhere but when it does come
to grinding through logfiles (some several gigs in size) we had to go
with Perl. The string processing and regex matching was so much
faster. We couldn't get Ruby even close :frowning: Speed was essential, we
couldn't just sit around and wait for the process to complete.

GitHub - michaeledgar/ruby-boost-regex: Wraps Boost::Regex in a Ruby binding
might be useful, if it ends up being regex's that are the slowdown :slight_smile:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Ok here is a quick test that I hacked up. The data is a 2,659,800 line
639Mb text file. Some lines contain the string "FRED", count them

Here are the scripts

-- Perl
#!/usr/bin/env perl

use strict;
use warnings;

my $logfile = 'results201101.dat';
my $counter = 0;
open FILE, "<$logfile" or die $!;
while(my $line = <FILE>) {
  if($line =~ /FRED/) {
    $counter++;
  }
}
close(FILE);
print "$counter\n";

-- Ruby 1
counter = 0
File.open("results201101.dat").each do |line|
  if line =~ /FRED/
    counter += 1
  end
end

puts counter

-- Ruby 2
r = Regexp.new('FRED')

counter = 0
File.open("results201101.dat").each do |line|
  if r.match(line)
    counter += 1
  end
end

puts counter

-- Ruby 3
counter = 0
File.open("results201101.dat").each do |line|
  if line.index("FRED")
    counter += 1
  end
end

puts counter

Perl 5.12.3 vs Ruby 1.8.7

Perl real 0m3.759s user 0m3.182s sys 0m0.535s
Ruby 1 real 0m6.216s user 0m4.939s sys 0m0.711s
Ruby 2 real 0m5.888s user 0m5.121s sys 0m0.721s
Ruby 3 real 0m6.187s user 0m5.512s sys 0m0.609s

So Perl is nearly twice as fast as Ruby.

Perl 5.12.3 vs Ruby 1.9.2

Perl real 0m3.778s user 0m3.172s sys 0m0.539s
Ruby 1 real 0m7.745s user 0m6.736s sys 0m0.661s
Ruby 2 real 0m7.775s user 0m7.102s sys 0m0.642s
Ruby 3 real 0m6.444s user 0m5.793s sys 0m0.513s

Ruby actually gets worse!

The issue here is that the test file is not large (think gigabytes for
the real thing) or long (think 10s of millions of lines). Those
differences start to add up.

To be honest I suspect that it is more an issue with the regexes than
file io and the real regexes are much more complicated than just match
a string. I was a bit surprised that the index() wasn't faster.

We have to parse the files in a very short timeframe, if Perl hadn't
been fast enough I had a horrible feeling that we would be looking at
C or something. Ooo that would be fun :slight_smile:

···

On 19 September 2012 10:09, Carlos Agarie <carlos.agarie@gmail.com> wrote:

I'd like to know, too. I stumbled upon a similar problem, but it was long
ago.

I'd like to know, too. I stumbled upon a similar problem, but it was long
ago.

Ok here is a quick test that I hacked up. The data is a 2,659,800 line
639Mb text file. Some lines contain the string "FRED", count them

Let's see: that are 252 chars per line on average.

Here's how I generated the file:

$ ruby -e 'x="X"*243; 2_600_000.times {|i| printf
"%7d%s%s\n",i,x,rand(1000)==0 ? "FRED" : "OOOO" }' >results201101.dat

To be honest I suspect that it is more an issue with the regexes than
file io and the real regexes are much more complicated than just match
a string. I was a bit surprised that the index() wasn't faster.

Darn! Maybe encoding plays a role here. The pure IO is pretty fast
(see last test):

RUN 2
2659

real 0m3.520s
user 0m3.213s
sys 0m0.249s
./perl.pl
2659

real 0m2.220s
user 0m1.950s
sys 0m0.249s
./ruby-1.rb
2659

real 0m4.912s
user 0m4.383s
sys 0m0.498s
./ruby-2.rb

real 0m5.032s
user 0m4.336s
sys 0m0.639s
./ruby-3.rb

real 0m3.610s
user 0m3.276s
sys 0m0.312s
./ruby-4.rb
2659

real 0m5.004s
user 0m4.399s
sys 0m0.467s
./ruby-5.rb
2659

real 0m4.980s
user 0m4.430s
sys 0m0.451s
./ruby-6.rb
0

real 0m2.495s
user 0m2.012s
sys 0m0.420s

$ head -200 *.pl *.rb
==> perl.pl <==
#!/usr/bin/env perl

use strict;
use warnings;

my $logfile = 'results201101.dat';
my $counter = 0;
open FILE, "<$logfile" or die $!;
while(my $line = <FILE>) {
  if($line =~ /FRED/) {
    $counter++;
  }
}
close(FILE);
print "$counter\n";

==> ruby-1.rb <==
#!/usr/bin/env ruby

counter = 0
File.open("results201101.dat").each do |line|
  if line =~ /FRED/
    counter += 1
  end
end

puts counter

==> ruby-2.rb <==
#!/usr/bin/env ruby

r = Regexp.new('FRED')

counter = 0
File.open("results201101.dat").each do |line|
  if r.match(line)
    counter += 1
  end
end

==> ruby-3.rb <==
#!/usr/bin/env ruby

counter = 0
File.open("results201101.dat").each do |line|
  if line.index("FRED")
    counter += 1
  end
end

==> ruby-4.rb <==
#!/usr/bin/env ruby

count = 0

File.foreach "results201101.dat" do |line|
  count += 1 if /FRED/ =~ line
end

puts count

==> ruby-5.rb <==
#!/usr/bin/env ruby

count = 0

File.foreach "results201101.dat", encoding: "ASCII" do |line|
  count += 1 if /FRED/ =~ line
end

puts count

==> ruby-6.rb <==
#!/usr/bin/env ruby

count = 0

File.foreach "results201101.dat", encoding: "ASCII" do |line|
  # count += 1 if /FRED/ =~ line
end

puts count

And here's the test run

$ for i in {1..2}; do echo "RUN $i"; time fgrep -c FRED
results201101.dat; for f in ./*.pl ./*.rb; do echo "$f"; time "$f";
done; done

This was all on cygwin on a machine with plenty memory => likely no real IO.

Ah, it get's a tad better without regexp:

$ time ./ruby-7.rb
2659

real 0m3.432s
user 0m2.869s
sys 0m0.529s
$ cat ruby-7.rb
#!/usr/bin/env ruby

count = 0
f = 'FRED'

File.foreach "results201101.dat", encoding: "BINARY" do |line|
  count += 1 if line.include? f
end

puts count

Kind regards

robert

···

On Wed, Sep 19, 2012 at 11:41 AM, Peter Hickman <peterhickman386@googlemail.com> wrote:

On 19 September 2012 10:09, Carlos Agarie <carlos.agarie@gmail.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

PS: Here's probably a even more rubyesce solution - albeit not faster

$ cat ruby-8.rb
#!/usr/bin/env ruby

f = 'FRED'

puts File.foreach("results201101.dat").count {|line| line.include? f}

···

On Wed, Sep 19, 2012 at 1:29 PM, Robert Klemme <shortcutter@googlemail.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/