Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by rnd me View Post
    i think we all know why it's 12, but i will admit that when i pounded it out and pasted it into firebug without thinking i was expecting a 10 or 11...
    Yes, as I said, the result is not what most people (including you ) would expect. Felgall excepted, of course.

    I have to say that to me attempting to save a few bytes or a few milliseconds at the expense of clarity is not sensible.
    Last edited by Philip M; 05-24-2013 at 07:40 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  2. #17
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Quote Originally Posted by Philip M View Post
    I have to say that to me attempting to save a few bytes or a few milliseconds at the expense of clarity is not sensible.
    Very true.

    Think of all the time that will end up being wasted by people trying to figure out where the code that they can't properly read has gone wrong where they'd be able to see instantly if the code were written more clearly.

    Jslint reports the use of the ++ operator with a warning because using it when combined with other statements makes the code far less readable. When not combined with other statements +=1 is a workable substitute that is only one character longer. So if you replace all the ++i and i++ references with i+=1 (where i can be any variable name at all) then anywhere that the code breaks by making that substitution is going to confuse most people and increase the cost of maintaining the code by a large amount.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  3. #18
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Since the discussion already went low-level: How awesome would it be, if we could use inlined Assembler in Javascript?

  4. #19
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by Airblader View Post
    Since the discussion already went low-level: How awesome would it be, if we could use inlined Assembler in Javascript?
    I'd settle for some way to easily incorporate functions written in assembler or even in C/C++. Note the word "easily".

    Of course, now you would have to have machine-specific installations.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  5. #20
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by Airblader View Post
    Since the discussion already went low-level: How awesome would it be, if we could use inlined Assembler in Javascript?
    um, that's exactly what V8 does...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  6. #21
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Maybe that's what V8 compiles it into, but V8 certainly doesn't allow me in my role as a js developer to write some inline Assembler into my code – or did I miss such a big thing?

  7. #22
    New Coder
    Join Date
    Sep 2010
    Location
    High Wycombe, UK
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you all for your contributions. I have not been able to code what I want. I will re-read your comments and keep plugging away for a bit longer then give up and just tell you what I want!

    Thanks again,
    Morlaf
    Morlaf - Learning JavaScript!

  8. #23
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by Airblader View Post
    Maybe that's what V8 compiles it into, but V8 certainly doesn't allow me in my role as a js developer to write some inline Assembler into my code or did I miss such a big thing?
    yes and no. If you know how V8 works, and how to profile/debug/tune, you have pretty close control over things like unboxing, intArrays, hardwarde modulo, etc. It's not always intuitive, but it is very do-able.

    in fact, you can even see the assembly that V8 generates using some special options in node/chrome/v8. you need a custom compilation last time i checked, but it might be worth trying out if you know assembly.

    you can do it in an interactive console, so that each little snip of JS spits out the generated assembly produced by that snip. In that fashion, you can reasonably and actually deduce what does what, giving you tight control over execution performance.

    http://www.youtube.com/watch?v=UJPdh...7uR6IB&index=4

    the result? closely watching the assembly output can allow you to tweak your JS to within 15% of C++ execution speeds, at least in V8...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  9. #24
    Regular Coder
    Join Date
    Jan 2013
    Location
    Germany
    Posts
    578
    Thanks
    4
    Thanked 77 Times in 77 Posts
    Thanks, I'll check that out when I get the chance to!


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •