Moving string arrays into constants

19 views
Skip to first unread message

Dray Lacy

unread,
Mar 17, 2008, 9:58:45 PM3/17/08
to Ruby Faker
I noticed Faker was being wasteful by generating large arrays of
strings every time certain methods were called. Moving these into
constants gives a nice speed boost.

Here's 10,000 runs of Faker::Name.first_name:

Before 9.130000 0.020000 9.150000 (9.153857)
After 0.010000 0.000000 0.010000 (0.015488)

Check the moved_string_arrays_into_constants.patch file for the patch.

Cheers!
Message has been deleted

Benjamin Curtis

unread,
Mar 28, 2008, 11:37:45 AM3/28/08
to Ruby Faker
Thanks for submitting the patch, Dray. The main reason I put the
arrays in methods rather than in constants was to make it super easy
for someone to customize the lists. Perhaps that's not a compelling-
enough reason considering the speed disadvantage?


----
Benjamin Curtis
http://catchthebest.com/ - Track, share, and rate incoming resumes
http://www.bencurtis.com/ - Personal blog
Reply all
Reply to author
Forward
0 new messages