This project is archived and is in readonly mode.

#723 ✓resolved
Emilio Tagua

Grouping helpers should use yield instead of block

Reported by Emilio Tagua | July 29th, 2008 @ 11:09 PM

Grouping helpers are using &block as parameter, yield should be used when possible so no new Procs are created.

I did some benchmark to confirm this and as you can see there is a better performance when using yield.

All tests still pass, of course.

Using yield:

Rehearsal ---------------------------------------------------------

test_split_with_block 6.100000 0.050000 6.150000 ( 6.839069)

------------------------------------------------ total: 6.150000sec

user system total real

test_split_with_block 6.120000 0.040000 6.160000 ( 7.529286)

Rehearsal ---------------------------------------------------------------------

test_in_groups_of_without_padding 4.190000 0.030000 4.220000 ( 4.498870)

------------------------------------------------------------ total: 4.220000sec

user system total real

test_in_groups_of_without_padding 4.210000 0.030000 4.240000 ( 4.789496)

Using block:

Rehearsal ---------------------------------------------------------

test_split_with_block 7.090000 0.060000 7.150000 ( 7.868116)

------------------------------------------------ total: 7.150000sec

user system total real

test_split_with_block 7.130000 0.050000 7.180000 ( 8.359386)

Rehearsal ---------------------------------------------------------------------

test_in_groups_of_without_padding 4.850000 0.030000 4.880000 ( 5.039969)

------------------------------------------------------------ total: 4.880000sec

user system total real

test_in_groups_of_without_padding 4.810000 0.030000 4.840000 ( 5.156383)

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages