Comment #7 on issue 2275 by [email protected]: Disappointingly bad switch performance on V8
http://code.google.com/p/v8/issues/detail?id=2275

Just to get a few more data points, I've hacked the original benchmark.js to use an array for dispatching (see attachment). The numbers on the various browsers:

   Firefox 14.0.1:      switch = 66 calls/sec, array = 37 calls/sec
   Chrome 21.0.1180.57: switch =  4 calls/sec, array = 46 calls/sec
   Chrome 22.0.1230.0:  switch =  4 calls/sec, array = 55 calls/sec

This means that using arrays instead of a switch statement is currently your best bet, it works OK on both browsers. I guess that the performance impact of the dispatch mechanism gets more negligible when the various cases do more than just returning a constant value.

Note that I'm not stating that v8 shouldn't do better for switches, but this probably won't happen in the near future, so don't hold your breath.

Attachments:
        benchmark-array.js  8.3 KB

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to