News for hackers. Stuff that matters.
Re:Primg – Generate prime numbers whose binary representatio... by Retr0spectrum on Monday January 29, 2018 @09:03PM (#16262331)
You could probably speed things up a lot using isProbablePrime(), at least to pre-filter candidate numbers. (Assuming you're using this library: https://www.npmjs.com/package/big-integer#isprobableprimeite...)
Re:Primg – Generate prime numbers whose binary representatio... by geonnave on Monday January 29, 2018 @09:10PM (#16262371)
I used isProbablePrime() before, when I had a 50x50 canvas. But it was still really really really slow. After changing to a 32x32 canvas, the difference between isPrime() and isProbablePrime() seemed negligible.
Re:Primg – Generate prime numbers whose binary representatio... by schoen on Monday January 29, 2018 @10:00PM (#16262573)
That makes me think that their probable prime implementation isn't that great or else that they're losing a ton of efficiency to the Javascript interpreter.

  $ time python -c 'import gmpy; gmpy.next_prime(2**2500)'
  
  real	0m0.443s
Was it taking a lot longer than that for you?

Edit: I can see that there is an element of luck in terms of how many candidates you have to look at, but I'm still seeing everything in this size range take under 2 seconds. Maybe it's a question of what probability of error you're accepting from the test?

Re:Primg – Generate prime numbers whose binary representatio... by johndough on Tuesday January 30, 2018 @03:27AM (#16263761)
GMP is very well optimized and implemented in assembly. There's no way that a JavaScript implementation can get anywhere close to that performance since JavaScript doesn't even have support for 64 bit integers. WebAssembly might be faster, but is still lacking many instructions commonly used for big integer arithmetic.
Re:Primg – Generate prime numbers whose binary representatio... by Retr0spectrum on Monday January 29, 2018 @09:12PM (#16262380)
Interesting. I guess in that case the only way to speed it up is with multithreading and/or asm.js.