# Re: Small optimization tips

**URL:** <https://www.ruby-forum.com/t/re-small-optimization-tips/81831>\
**Category:** Ruby\
**Created:** [March 14, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/re-small-optimization-tips/81831 "2006-03-14T20:01:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 14, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/re-small-optimization-tips/81831/1 "2006-03-14T20:01:51Z")

</div>

I made a script run 800% faster by using the Time class instead of the  
DateTime class. You can see the scripts and more details at  
[http://www.recentrambles.com/pragmatic/view/33](http://www.recentrambles.com/pragmatic/view/33) Also, using a “memoize”  
function whenever possible can greatly increase performance.

I’m still new to ruby, but what does this mean?

On Wed, 2006-03-15 at 03:53 +0900, Vincent F. wrote:

> - Using a Set instead of an Array when you only want to store unique  
> values can help make your code go faster

Charlie B.  
[http://www.recentrambles.com](http://www.recentrambles.com)

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 14, 2006, 8:04pm UTC](https://www.ruby-forum.com/t/re-small-optimization-tips/81831/2 "2006-03-14T20:04:59Z")

</div>

On Mar 14, 2006, at 12:59 PM, Charlie B. wrote:

> I’m still new to ruby, but what does this mean?

The Set library is a standard library that comes with Ruby. I  
believe it uses rbtree if it can be loaded or a plain Hash otherwise,  
but it supports the expected set operations and keeps the contents  
unique.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 14, 2006, 8:20pm UTC](https://www.ruby-forum.com/t/re-small-optimization-tips/81831/3 "2006-03-14T20:20:18Z")

</div>

Thanks, I’ll look that up in the pickaxe book when I get home.

On Wed, 2006-03-15 at 04:04 +0900, James Edward G. II wrote:

> 

Charlie B.  
Programmer  
Castle Branch Inc.

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 14, 2006, 8:57pm UTC](https://www.ruby-forum.com/t/re-small-optimization-tips/81831/4 "2006-03-14T20:57:16Z")

</div>

On Wed, 15 Mar 2006, James Edward G. II wrote:

> On Mar 14, 2006, at 12:59 PM, Charlie B. wrote:
> 
> > I’m still new to ruby, but what does this mean?
> 
> The Set library is a standard library that comes with Ruby. I believe it  
> uses rbtree if it can be loaded or a plain Hash otherwise, but it supports  
> the expected set operations and keeps the contents unique.

when, oh when, will rbtree be in the core… sigh.

-a

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 14, 2006, 8:26pm UTC](https://www.ruby-forum.com/t/re-small-optimization-tips/81831/5 "2006-03-14T20:26:21Z")

</div>

Ah thanks about the Time class. The script I wrote deals with dates,  
and I was using Date.strptime. Switching to Time.gm increased the  
speed of the script by 4x.

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 14, 2006, 9:15pm UTC](https://www.ruby-forum.com/t/re-small-optimization-tips/81831/6 "2006-03-14T21:15:46Z")

</div>

removed\_email\_address@domain.invalid wrote:

> when, oh when, will rbtree be in the core… sigh.
> 
> -a

and it would be nice for it to have some more methods, like #slice! (a  
destructive version of #bound).

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 14, 2006, 9:31pm UTC](https://www.ruby-forum.com/t/re-small-optimization-tips/81831/7 "2006-03-14T21:31:05Z")

</div>

On Mar 14, 2006, at 1:57 PM, removed\_email\_address@domain.invalid wrote:

> when, oh when, will rbtree be in the core… sigh.

Isn’t it the library someone was complaining is broken in Ruby  
1.8.4? We might need to fix it first.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 14, 2006, 9:40pm UTC](https://www.ruby-forum.com/t/re-small-optimization-tips/81831/8 "2006-03-14T21:40:44Z")

</div>

James Edward G. II wrote:

> Isn’t it the library someone was complaining is broken in Ruby 1.8.4?  
> We might need to fix it first.

Did you mean ruby-talk:183166 ? I’ve been using rbtree happily on 1.8.4.

---

<div class="post-metadata">

**Author:** ![beachguy82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9dc877/32.png) [@beachguy82](https://www.ruby-forum.com/u/beachguy82)\
**Post date:** [March 14, 2006, 9:47pm UTC](https://www.ruby-forum.com/t/re-small-optimization-tips/81831/9 "2006-03-14T21:47:51Z")

</div>

On Mar 14, 2006, at 2:39 PM, Joel VanderWerf wrote:

> James Edward G. II wrote:
> 
> > Isn’t it the library someone was complaining is broken in Ruby 1.8.4?  
> > We might need to fix it first.
> 
> Did you mean ruby-talk:183166 ? I’ve been using rbtree happily on  
> 1.8.4.

Oops, yeah, my memory was poor on that one. It looks like it might  
be broken on 1.8.2, not 1.8.4. Sorry. My bad.

James Edward G. II
