Loading ...
Sorry, an error occurred while loading the content.

885Re: Save and restore jslint settings

Expand Messages
  • aseem.kishore@ymail.com
    Sep 4, 2009
    • 0 Attachment
      For what it's worth, some of the code I write does indeed run in a tight loop many times (striving for 60 frames/sec), and low-level optimizations have proven to help (especially in IE).

      For curiosity's sake, I did some testing between bit-shifting and regular math, and it seems bit-shifting is in fact faster for the cases I use.

      Using these two functions, with i going from 0 to 50000:

      function pow2BitShifting(i) {
      var x = 1 << (i % 30);
      }

      function pow2RegularMath(i) {
      var x = Math.pow(2, (i % 30));
      }

      In Firefox:

      Powers of 2 w/ bit shifting: 38 msecs
      Powers of 2 w/ regular math: 69 msecs

      In IE:

      Powers of 2 w/ bit shifting: 56 msecs
      Powers of 2 w/ regular math: 107 msecs

      In Chrome and Safari (nearly identical here):

      Powers of 2 w/ bit shifting: 2 msecs (!!)
      Powers of 2 w/ regular math: 16 msecs

      So anyway, it's clear that using bitwise operators has its place, so to get back to the original topic, it would be great if I could opt-in on a per-function basis. =)

      Aseem

      --- In jslint_com@yahoogroups.com, "christian.wirkus" <christian.wirkus@...> wrote:
      >
      > Sure. Write what is understood best. That's what code quality is about, I think.
      > I just wanted to mention that bitwise operators in Javascript are not as efficient as in other languages (because I read bitwise and optimized so close to one another). And often are used for gaining performance only.
      > And I thought of something like this:
      > var x = 2;
      > x * 2 === x << 1;
      >
      > If there is a context where bitwise is a clear and short solution to a problem, use it.
      >
      > Christian
      >
      >
      > --- In jslint_com@yahoogroups.com, Paul Novitski <paul@> wrote:
      > >
      > >
      > > >--- In jslint_com@yahoogroups.com, "christian.wirkus"
      > > ><christian.wirkus@> wrote:
      > > > > Are you sure bitwise operators optimize anything in Javascript?
      > > > > Javascript isn't C, and the data type number is 64 bit float, not integer.
      > >
      > > At 9/2/2009 10:24 AM, aseem.kishore@ wrote:
      > > ...
      > > >I'm also not sure about whether that indeed optimizes anything. I
      > > >haven't done profiling comparisons; I'm just reusing well-known algorithms.
      > >
      > >
      > >
      > > Christian, my guess is that the reasoning behind your comment is an
      > > assumption that Aseem would choose bit-manipulation primarily to
      > > optimize the code on a low level. From Aseem's reply that doesn't
      > > appear to be the case. He's using algorithms because they're
      > > dependable and do the job without regard for how they work on a low
      > > level, and that's interesting.
      > >
      > > I offer the opinion that, unless a particular language structure
      > > occurs in a loop that iterates an enormous number of times, low-level
      > > optimization is irrelevant compared to the importance of its
      > > usability in the high-level script.
      > >
      > > (Can we get away with calling usability high-level or human-level
      > > optimization?)
      > >
      > > If a bit of syntax is easy to use, read, proofread, and modify, then
      > > it wins. The whole purpose of high-level scripts such as JavaScript
      > > is their human benefit only; the computers don't care, they would run
      > > binary machine code much more quickly. But these days the chips are
      > > so bloody fast that it takes a lot of inefficiency to make their
      > > round trips perceptible to our own slow-poke bags of brain jelly.
      > >
      > > Regards,
      > >
      > > Paul
      > > __________________________
      > >
      > > Paul Novitski
      > > Juniper Webcraft Ltd.
      > > http://juniperwebcraft.com
      > >
      >
    • Show all 13 messages in this topic