r/ProgrammerHumor • • Jun 21 '18

Thanks Brendan for giving us the Javascript

Post image
3.1k Upvotes

302 comments sorted by

View all comments

Show parent comment

6

u/once-and-again ☣️ Jun 21 '18

In theory, yes, it would be slower for things that only need integers. In practice, there are so many other things that slow JS execution down so much more that this probably isn't a bottleneck worth worrying about.

If you're doing serious number-crunching, you don't use JS — you use something compiled to native code, possibly with the sticky parts written in hand-optimized assembler.

1

u/SasDerGrosse Jun 22 '18

Oh alright, thanks for letting me know!

Another question: do people still write assembly code nowadays? I thought compilers do most of the necessary optimisations automatically.

2

u/once-and-again ☣️ Jun 22 '18

Not often, but it does happen. There are a rare few times when you know more about your code than you can explain to the compiler; there are a rare few times within that when that actually matters enough to bother with writing assembler.

Usually this isn't just for speed's sake when number-crunching. (That does happen, but only about once in a month's worth of blue moons.) The case I've most commonly seen is where you need to avoid a possible side-channel attack in your cryptography code — usually timing differences on different inputs — and so have to hand-write it in assembler to prevent dangerous optimizations while retaining the safer ones.

This is all library stuff, though. Application logic is basically only written in assembler if you're showing off.