Giter Site home page Giter Site logo

Comments (3)

oberstet avatar oberstet commented on May 7, 2024

I can see only 1 potential benefit which might be worth: performance.

However, is .toString(36) working on all browsers?

Have you benchmarked that something like return Math.random().toString(36).substr(2,16); is actually faster than the loop?

from autobahn-js.

Incognito avatar Incognito commented on May 7, 2024

Number.toString(36) has been supported since the early days so we should have it in IE.

I ran some jsPerf tests and the shorter code came out about 10%-20% faster: http://jsperf.com/randomstring-tostring-and-for

The other advantage here is a less complex code base (even if it's marginally so). If the . artifact doesn't bother you, it also improves the speed.

from autobahn-js.

oberstet avatar oberstet commented on May 7, 2024

First off, the jsPerf site is really cool! Didn't know that.

Now, I also did some tests: http://jsperf.com/generate-random-id/2

Results:

  • with Firefox the modified ID function is slower than the current one
  • all other browsers tested were faster
  • the variant with most consistent performance across browsers is variant 4

In any case, we are talking about 300k ops/s even for the slowest (Opera with existing function). In practice, it won't matter at all.

I don't bother about code .. it's trivial in any of the variants.

If you still care, send me a pull with a new function ab._newidFast (leaving the old function there/untouched) with implementation return Math.random().toString(36); and change the single line where it is called to call that new function. Add a link to above perf test in a code comment. I'd merge that ..

Thanks!

from autobahn-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.