# Is faster using abbreviated parameter names?

**URL:** <https://www.ruby-forum.com/t/is-faster-using-abbreviated-parameter-names/161829>\
**Category:** Ruby\
**Created:** [March 2, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/is-faster-using-abbreviated-parameter-names/161829 "2009-03-02T21:50:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [March 2, 2009, 9:50pm UTC](https://www.ruby-forum.com/t/is-faster-using-abbreviated-parameter-names/161829/1 "2009-03-02T21:50:50Z")

</div>

Hi, a simple question:

a)  
def hello(string)  
# stuff with ‘string’  
end

b)  
def hello(s)  
# stuff with ‘s’  
end

Will be b) faster since the parameter name contains less letters?

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [March 2, 2009, 9:56pm UTC](https://www.ruby-forum.com/t/is-faster-using-abbreviated-parameter-names/161829/2 "2009-03-02T21:56:47Z")

</div>

On 02.03.2009 21:48, Iñaki Baz C. wrote:

> end
> 
> Will be b) faster since the parameter name contains less letters?

I have no idea. I guess not. But you can easily verify for yourself.  
Just write up a little program using Benchmark and you’ll soon know.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [March 2, 2009, 10:08pm UTC](https://www.ruby-forum.com/t/is-faster-using-abbreviated-parameter-names/161829/3 "2009-03-02T22:08:31Z")

</div>

El Lunes, 2 de Marzo de 2009, Robert K.  
escribió:\> \> # stuff with ‘s’

> > end
> > 
> > Will be b) faster since the parameter name contains less letters?
> 
> I have no idea. I guess not. But you can easily verify for yourself.  
> Just write up a little program using Benchmark and you’ll soon know.

Yes, doing a benchmark the result is more or less the same (any other  
factor  
seems to be more important), but what I want to know is what should be  
the  
response based on how Ruby works. Under my understanding Ruby needs to  
parse  
during runtime the variable name so a longer variable name would require  
more  
time, am I wrong?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [March 2, 2009, 10:27pm UTC](https://www.ruby-forum.com/t/is-faster-using-abbreviated-parameter-names/161829/4 "2009-03-02T22:27:54Z")

</div>

IÃ±aki Baz C. wrote:

> Yes, doing a benchmark the result is more or less the same (any other  
> factor  
> seems to be more important), but what I want to know is what should be  
> the  
> response based on how Ruby works. Under my understanding Ruby needs to  
> parse  
> during runtime the variable name so a longer variable name would require  
> more  
> time, am I wrong?

I believe you’re wrong.

Symbols are resolved into references to the symbol table at parse time,  
so when running, :s and :ssssssssssssssss are just two different  
pointers into the same symbol table. As for local variables, they are  
just offsets into the stack frame.

So it might take a microscopically small amount of extra time for your  
program to start up, reading a few extra bytes of source code, but once  
it’s running, each iteration should take the same time.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [March 2, 2009, 10:09pm UTC](https://www.ruby-forum.com/t/is-faster-using-abbreviated-parameter-names/161829/5 "2009-03-02T22:09:42Z")

</div>

And how much faster would it have to be to make it worth it to use a  
meaningless name versus a meaningful one?

Smells like premature optimization to me…

Cheers,

dwh

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [March 3, 2009, 12:05am UTC](https://www.ruby-forum.com/t/is-faster-using-abbreviated-parameter-names/161829/6 "2009-03-03T00:05:41Z")

</div>

El Lunes, 2 de Marzo de 2009, Brian C. escribiÃ³:

> I believe you’re wrong.
> 
> Symbols are resolved into references to the symbol table at parse time,  
> so when running, :s and :ssssssssssssssss are just two different  
> pointers into the same symbol table. As for local variables, they are  
> just offsets into the stack frame.
> 
> So it might take a microscopically small amount of extra time for your  
> program to start up, reading a few extra bytes of source code, but once  
> it’s running, each iteration should take the same time.

Thanks, that makes sense 🙂

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [March 3, 2009, 1:16am UTC](https://www.ruby-forum.com/t/is-faster-using-abbreviated-parameter-names/161829/7 "2009-03-03T01:16:00Z")

</div>

Good to hear.

It’s just remarkable how lots of people start at the end and work their  
way backwards… 😉

dwh

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [March 3, 2009, 12:07am UTC](https://www.ruby-forum.com/t/is-faster-using-abbreviated-parameter-names/161829/8 "2009-03-03T00:07:26Z")

</div>

El Lunes, 2 de Marzo de 2009, Denis H. escribiÃ³:

> And how much faster would it have to be to make it worth it to use a  
> meaningless name versus a meaningful one?
> 
> Smells like premature optimization to me…

Sure, it was just curiosity 🙂  
I will not code in Ruby to get a unreadable code like in other languages  
🙂
