Or how two chars make the difference. A tale on my current project.

While debugging a current app, I decided to start camping with $DEBUG
= true. Suddenly, while loading a page, exceptions I have never seen
started flowing in the console like the crocodiles in the river of the
frogger game. This is because when $DEBUG is set to true, even
handled/catched exceptions are printed to the console (but not the
backtrace).

This reminded me of "[href,:action,:src].map{|a|(h[a]=self/h[a])rescue
0". This is the line that escapes all urls to put them on the right
path.

Small instrumentation later, my page was generating 284! exceptions,
with each a backtrace size of 65 in avg.

By adding: 2 characters

From:
  [:href,:action,:src].map{|a|(h[a]=self/h[a])rescue 0}
To:
  [:href,:action,:src].map{|a|(h[a]&&=self/h[a])rescue 0}

The exceptions dropped to 39

Finally, the poor man benchmark:

[EMAIL PROTECTED] swarm]$ camping myapp.rb
** "myapp" app loaded
** Starting Mongrel on 0.0.0.0:3301
  0.120000   0.010000   0.130000 (  0.137303)
  0.070000   0.010000   0.080000 (  0.086835)
  0.060000   0.010000   0.070000 (  0.080585)
  0.110000   0.010000   0.120000 (  0.127002)
  0.070000   0.020000   0.090000 (  0.081667)
[EMAIL PROTECTED] swarm]$ camping myapp.rb
** "myapp" app loaded
** Starting Mongrel on 0.0.0.0:3301
  0.050000   0.010000   0.060000 (  0.068349)
  0.040000   0.010000   0.050000 (  0.057737)
  0.040000   0.010000   0.050000 (  0.057360)
  0.040000   0.010000   0.050000 (  0.057386)
  0.040000   0.010000   0.050000 (  0.057580)

Source : http://github.com/zimbatm/camping/tree/master

Cheers,
  zimbatm
_______________________________________________
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to