How to speed up ruby and make it as fast as possible

Write it C.

I find this answer to be unsatisfactory. I do not know C and neither do
many others who like Ruby but want better performance. The knowledge
and syntax demands of programming in Ruby and C are worlds apart. It is
not much different than telling someone to go code in (modern)
Assembler!

I think the more that Rubyists acknowledge and try to directly solve the
language's performance hindrance rather than rationalizing it away, the
better the prospects for the success of our beloved language. Of
course, better algorithms can produce better performance, but that
argument is also true for the languages with which Ruby compares
unfavorably in performance. Please do not claim that Ruby's adoption by
others is irrelevant: a good idea is worth spreading, and the more
users, the better library support and learning resources available to us
all.
Also, please do not tell me to rewrite Ruby, myself, if I care about
performance. As stated, I do not know C or have the interest and time
to devote to such an undertaking. I do promote Ruby to friends and
colleagues in ways that I can. We should be able to have a legitimate
desire for language improvements without being characterized as
ignoramuses, nay-sayers or lazy spectators.

Regards,
Jamal

···

-----Original Message-----
From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf
Of Reggie Mr
Sent: Friday, July 14, 2006 6:56 AM

I find this attitude is quite amazing. We all know that Ruby is not a
best language in terms of performance. Even if we had Ruby 2.0 (YARV)
delivered to us, Ruby's performance would still be a way behind those
strong typed languges like ocaml or java. If you want to keep using
Ruby, but sometimes you need a raw performance, you should learn C.
It's not that bad, you know. If you always need a raw performance,
then probably you are not using right tool for the job.

just my 2 cents.

···

On 7/14/06, Jamal Mazrui <Jamal.Mazrui@fcc.gov> wrote:

-----Original Message-----
From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf
Of Reggie Mr
Sent: Friday, July 14, 2006 6:56 AM

> Write it C.

I find this answer to be unsatisfactory. I do not know C and neither do
many others who like Ruby but want better performance. The knowledge
and syntax demands of programming in Ruby and C are worlds apart. It is
not much different than telling someone to go code in (modern)
Assembler!

I think the more that Rubyists acknowledge and try to directly solve the
language's performance hindrance rather than rationalizing it away, the
better the prospects for the success of our beloved language. Of
course, better algorithms can produce better performance, but that
argument is also true for the languages with which Ruby compares
unfavorably in performance. Please do not claim that Ruby's adoption by
others is irrelevant: a good idea is worth spreading, and the more
users, the better library support and learning resources available to us
all.
Also, please do not tell me to rewrite Ruby, myself, if I care about
performance. As stated, I do not know C or have the interest and time
to devote to such an undertaking. I do promote Ruby to friends and
colleagues in ways that I can. We should be able to have a legitimate
desire for language improvements without being characterized as
ignoramuses, nay-sayers or lazy spectators.

Regards,
Jamal

--
Kent
---

We all want Ruby to be faster but if the speed at which your application runs at is your priority then I'm afraid that Ruby is not good enough. Neither is Python, Perl, Java or any other language. In extremis even C isn't good enough and only assembler will do.

Please do not sell Ruby as the Golden Hammer that can do anything better than any other language, it quite clearly cannot do that. You will do Ruby a disservice and people will question your ability to make a sound technical judgement.

Of course there are many things that you can do to make a Ruby program faster, like writing better code :slight_smile:

A programming language is simply a tool and not everything is a nail.

I prefer to use Ruby for _most_ of my programming work, but still
couldn't imagine using it for every single task. It's just one tool of
many. And the more of these tools you can pick up and use that much
better of a craftsman you will be.

That being said, I would strongly recommend you do learn C. The Ruby
interpreter relies on it, Ruby has a very clean, logical interface with
it, and learning it would allow you to tap into a whole other world of
available libraries. Just review some of Pickaxe for basic details
about how it can help make your life easier, not more complex. Plus, as
others have mentioned, learning it would allow to use it for
performance critical portions of your work.

Bad analogy maybe, but being a programmer and not knowing any C is like
a guitarist now knowing any Led Zeppelin :slight_smile:

Jamal Mazrui wrote:

···

-----Original Message-----
From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf
Of Reggie Mr
Sent: Friday, July 14, 2006 6:56 AM

> Write it C.

I find this answer to be unsatisfactory. I do not know C and neither do
many others who like Ruby but want better performance. The knowledge
and syntax demands of programming in Ruby and C are worlds apart. It is
not much different than telling someone to go code in (modern)
Assembler!

I think the more that Rubyists acknowledge and try to directly solve the
language's performance hindrance rather than rationalizing it away, the
better the prospects for the success of our beloved language. Of
course, better algorithms can produce better performance, but that
argument is also true for the languages with which Ruby compares
unfavorably in performance. Please do not claim that Ruby's adoption by
others is irrelevant: a good idea is worth spreading, and the more
users, the better library support and learning resources available to us
all.
Also, please do not tell me to rewrite Ruby, myself, if I care about
performance. As stated, I do not know C or have the interest and time
to devote to such an undertaking. I do promote Ruby to friends and
colleagues in ways that I can. We should be able to have a legitimate
desire for language improvements without being characterized as
ignoramuses, nay-sayers or lazy spectators.

Regards,
Jamal

Jamal Mazrui wrote:

From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf
Of Reggie Mr
Sent: Friday, July 14, 2006 6:56 AM

Write it C.
    
I find this answer to be unsatisfactory. I do not know C and neither do
many others who like Ruby but want better performance. The knowledge
and syntax demands of programming in Ruby and C are worlds apart. It is
not much different than telling someone to go code in (modern)
Assembler!

I think the more that Rubyists acknowledge and try to directly solve the
language's performance hindrance rather than rationalizing it away, the
better the prospects for the success of our beloved language. [snip]
  

I don't think people are ignoring Ruby's performance or rationalizing it away. That's why all that work is going into YARV for Ruby2. That's why there is ruby2c. There are people who are consciously working towards a better performing Ruby. As far as I understand it, there is plenty of room for Ruby to improve (performance has not been a top priority previously), so I have no doubt that we will see a faster Ruby in the future.

However, if you want an immediate solution, then the solution is to use another language or link to another language from Ruby. The helpful people on this list are also very practical, so when someone says, "How do I make my Ruby program run faster?" instead of answering, "Sorry, you can't" they give practical advice.

Sorry to be blunt, but if you are not contributing to improving Ruby's performance, then you (and I :slight_smile: will need to be patient and wait for the newer, faster, even more awesome versions of Ruby to come out.

-Justin

···

-----Original Message-----

"I find this answer to be unsatisfactory. I do not know C and neither do
many others who like Ruby but want better performance. The knowledge
and syntax demands of programming in Ruby and C are worlds apart. It is
not much different than telling someone to go code in (modern)
Assembler! "

Assembler is not that bad either, imho once you've learned how to program beyond just a specific language picking up another one is not that challenging. And i agree learn c it's at the very least good for very speed important tasks, or interfacing directly with the os or writing ruby modules to do said interfacing.

I mean try to beat this thing in speed *need an x86 compiler*

.model small

.stack 100h

.386

Bufsize= 800

bsize=800

.data

ten DD 10

FACT DD Bufsize DUP(0)

INDEX dd 0

MULTI DD 0

LEN DD 1

.code

main proc far

    mov ax,@data

    mov ds,ax

    mov ah,62h

    int 21h

    mov es,bx

    mov eax,0

    mov ebx,081h

    movzx ecx,BYTE PTR es:[80h]

L4: mul ten

    movzx edx,BYTE PTR es:[ebx]

    and edx,000000fh

    add eax,edx

    inc ebx

    loop L4

;put code here

        MOV ESI,OFFSET FACT

         MOV [ESI],EAX

         DEC EAX

         MOV ECX,EAX

         CMP ECX,0

         JE PEAX

Fac1:

     MOV EBX,0

     MOV ESI,OFFSET FACT

     MOV INDEX,0

Fac2:

     MOV EAX,[ESI] ;MOV FACT INTO EAX

     MUL ECX ;MUL BY COUNT

     ADD EAX,EBX ;ADD CONTENTS OF EBX TO ECX

     JNC Fac3 ;NO CARRY => JUMP L3

     INC EDX ;OTHERWISE INC EDX

Fac3:

     MOV EBX,EDX ;MOV CONTENT OF EDX TO EBX

     MOV [ESI],EAX ;STORE MUL RESULT IN CURRENT ESI POS

     INC INDEX

     MOV EAX,INDEX

     CMP LEN,EAX ;COMPARE LEN, INDEX

     JNE Fac5 ;NOT EQUAL => JUMP L2

     CMP EBX,0 ;COMPARE FOR CARRY AFTER ADD ECX,EBX

     JZ Fac4 ;NO CARRY => JUMP L4

     INC LEN ;INC LEN

     ADD ESI,4

     MOV [ESI],EBX

     JMP Fac4

Fac5:

     ADD ESI,4

     JMP Fac2

Fac4:

     LOOP Fac1

mov INDEX,0

mov ESI,OFFSET FACT

MK1:

mov eax,[esi]

push eax

inc INDEX

add esi,4

mov ecx,INDEX

cmp ecx, LEN

jnz MK1

;end code

PEAX:

    pop eax

    mov ebx,eax

    mov ecx,8

    cmp INDEX,0

    jz I1

L9:

L3:

        mov edx,0f0000000h

    and edx,ebx

    push ecx

    mov cl,28

        shr edx,cl

    pop ecx

    mov ah,02h

    cmp dl,10

    jb L1

    add dl,37h

        jmp L2

L1: or dl,30h

L2: int 21h

    shl ebx,1

    shl ebx,1

    shl ebx,1

    shl ebx,1

    loop L3

    dec INDEX

    cmp INDEX,0

    jnz PEAX

    mov ah,4ch

    int 21h

I1:

    inc INDEX

    jmp L9

main endp

end main

Kent Sibilev wrote:

···

I find this attitude is quite amazing. We all know that Ruby is not a
best language in terms of performance. Even if we had Ruby 2.0 (YARV)
delivered to us, Ruby's performance would still be a way behind those
strong typed languges like ocaml or java. If you want to keep using
Ruby, but sometimes you need a raw performance, you should learn C.
It's not that bad, you know. If you always need a raw performance,
then probably you are not using right tool for the job.

just my 2 cents.

On 7/14/06, Jamal Mazrui <Jamal.Mazrui@fcc.gov> wrote:

-----Original Message-----
From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf
Of Reggie Mr
Sent: Friday, July 14, 2006 6:56 AM

> Write it C.

I find this answer to be unsatisfactory. I do not know C and neither do
many others who like Ruby but want better performance. The knowledge
and syntax demands of programming in Ruby and C are worlds apart. It is
not much different than telling someone to go code in (modern)
Assembler!

I think the more that Rubyists acknowledge and try to directly solve the
language's performance hindrance rather than rationalizing it away, the
better the prospects for the success of our beloved language. Of
course, better algorithms can produce better performance, but that
argument is also true for the languages with which Ruby compares
unfavorably in performance. Please do not claim that Ruby's adoption by
others is irrelevant: a good idea is worth spreading, and the more
users, the better library support and learning resources available to us
all.
Also, please do not tell me to rewrite Ruby, myself, if I care about
performance. As stated, I do not know C or have the interest and time
to devote to such an undertaking. I do promote Ruby to friends and
colleagues in ways that I can. We should be able to have a legitimate
desire for language improvements without being characterized as
ignoramuses, nay-sayers or lazy spectators.

Regards,
Jamal

class LedZep < Rock::Default
    ripoff(Blues)
    include Tolkein::References::Tedious
    acts_as_pretentious
    has(slavering_adulation_of(:ignorant))
  end

  Flame::on!

:slight_smile:

Regards,

Jeremy Henty

···

On 2006-07-14, gregarican <greg.kujawa@gmail.com> wrote:

... being a programmer and not knowing any C is like a guitarist now
knowing any Led Zeppelin :slight_smile:

Ouch. That hurt :-/ Maybe I should've said a programmer not knowing C
would be like a southern U.S. redneck (of which I am one) not knowing
the song "Freebird."

Jeremy Henty wrote:

···

On 2006-07-14, gregarican <greg.kujawa@gmail.com> wrote:

> ... being a programmer and not knowing any C is like a guitarist now
> knowing any Led Zeppelin :slight_smile:

  class LedZep < Rock::Default
    ripoff(Blues)
    include Tolkein::References::Tedious
    acts_as_pretentious
    has(slavering_adulation_of(:ignorant))
  end

  Flame::on!

:slight_smile:

Regards,

Jeremy Henty