Hacker News new | comments | show | ask | jobs | submit login

The spectral norm test appears to be wrong. On C++ & Java it gets the math expression in the A function wrong, and produces NaN, which apparently has a huge performance cost. Taking the correct version from the Javascript (and converting to a double correctly) gives the correct result, and (OpenJDK) Java runs twice as fast.

Kannan, if you want to fix it, the Java diff is:

- return ((double)1)/((i+j)(i+j+1)/((double)2+i+1));

+ return 1.0/((i+j)(i+j+1)/2+i+1);

That gives the same count as the JS. It'd be interesting to know whether Dalvik/ARM has the same performance hit on NaN!


I think the "/2" should be a "/((double)2)", since in C and Java it'll treat the former as a truncated int divide. I do see the issue with the precedence on the 2+i+1, though. Will fix up and re-run.

You're quite right. You can also use 2.0

Fixed up and pushed to repo. If you see anything else that's incorrect, please feel free to let me know either by posting or through mail, and thanks again for pointing that out.

With the changes, the scores didn't change dramatically, and the asm.js version got a bit faster too, actually coming in closer to the native score than before, which is weird. Overall, scores got better across the board by about 8% or so.

The fact that asm.js does better now than it did before somehow suggests to me that there may be an issue in the NDK libc's malloc or free implementation, and that the better scores are simply allowing that issue to have more effect. This is another one of those programs which does a bunch of "biggish" allocs/frees repeatedly.

I'll put the updated charts up with an edit note shortly.

Hmm. Could you post the code for your corrected version?

I tried to find where a NaN would be introduced in the C++ and Java code, but I can't really spot it. The equation only has adds, multiplies, and divides, no negative numbers, and no divides by zero that I can see.

If you show me where the problem is, it wouldn't take me too long to re-run everything with the corrected code and update the results.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact