

Ruby vs PHP performance - luccastera
http://izumi.plan99.net/blog/index.php/2008/01/17/ruby-vs-php-performance/

======
carpal
I find it funny that the 31 lines of code in the example can be easily reduced
to 8:

    
    
      def merge(a, b)
        c = []
        c << (a[0] > b[0] ? b.shift : a.shift) until a.empty? || b.empty?
        return c+a+b
      end
    
      def mergesort(a)
        a.size <= 1 ? a : merge(mergesort(a.slice!(0,a.size/2)),mergesort(a))
      end
    

Language Power > Language Speed

~~~
mrtron
I also thought what was humorous was if you were using python, you wouldn't
use a python sorting algorithm for numbers. I realize it is just an example,
but if you want something realistic, use the built in sort which is nicely
optimized, or write your own method in C if it is non-trivial.

    
    
      >def realsort():
        t1 = datetime.datetime.now()
        for x in range(3000):
            numbers[:].sort()
        t2 = datetime.datetime.now()
        print t2-t1
      >realsort()
      >0:00:00.128081

------
randallsquared
I would assume that one reason PHP seems faster in practice is that much of
the typical grunt work of a webapp (what he calls the "web environment") is
done in C for PHP and Ruby for Ruby.

------
dzorz
C++ version is a disaster. It is literally two orders of magnitude slower than
it should be.

------
tx
The dude compared the performance of a couple of array-related functions in
various run time libraries for 4 languages, with all those functions
(probably) written in C. Although I still consider this exercise useful.

------
brlewis
The merge sort test is probably spending most of its time
allocating/deallocating arrays. I would say it's similar to the b-tree
shootout.

[http://shootout.alioth.debian.org/gp4/benchmark.php?test=bin...](http://shootout.alioth.debian.org/gp4/benchmark.php?test=binarytrees&lang=all)

------
troels
Comparing languages for speed is a really odd thing to do. It's much like
trying to compare the intelligence of people. Give a very narrow context, it
may be sort-of-do-able, but it's not a very useful picture. The problems with
PHP, is _not_ its speed.

~~~
Zak
It may be an odd thing to do, but it's a common thing to do. People are prone
to premature optimization, and that includes selecting a language. The
perception that the language that's otherwise optimal is too slow has resulted
in a number of projects being written in a suboptimal language.

------
mojuba
I once wrote a compiler and a VM for a custom language and without much
optimization it performed almost twice as fast as PHP. Not that I'm good at
VM's but probably PHP is really bad.

------
thomasfl
Ruby seems to be more than fast enough, but Rails and ActiveRecord is slow.

------
agentbleu
I find the debate about languages follows in a long line of others, first
going back to analog vs digital, vinyl vs CDs, film Vs DV, MS PC's vs Apple,
blar blar.

It would appear to me that most of this is driven by prejudice and stems back
to people like what they know, where they feel comfortable, and upstarts that
think they know better (the new kids on the block) have less bias, less
invested and are evangelists of the new because it's cool and they have a
chance of caving out a bit of respect if they can attain expert status in that
new field where they would have had no chance with the old fashioned.

I like php, simply because i find it easy to grasp, almost intuitive, but most
importantly is the community, who have within the documentation left their own
solutions and many tips are gained from this for me, along with a few other
resources I can normally find most things in PHP, thousands of classes already
written and open source, code examples etc.

I also do a fair bit with AS2 and this is a great platform but the community
is no where near as advanced, and the language can act very strange sometimes,
plus is also very tight and unforgiving.

I see no speed issues with PHP, no security problems (as often claimed) if you
code sensibly and I like it. so there.

------
ivan
This is needle debate. There could be 2 girls. Both with perfect bodies, wombs
and breasts but only with one of them is you sexual experience much better.
You don't know why is it so, you can't explain it ... because it's just the
chemistry. One love slow comfortable movements, other is like a rabbit :) Did
you ever seen the rabbit in action? Love PHP and give Ruby a chance.

~~~
shawndrost
SURREALIST TROLL STRIKES AGAIN

~~~
ivan
THX

