You asked for it … Riemann Zeta Function in javascript or node.js

Ok, this was fun. Its been a while since I dusted off good old rzf … ok, its been 12-ish days … but I really have been wanting to try recoding it in javascript.
As you might (or might not) remember, I asked questions (a very long time ago) about quality of generated code from a few different C compilers (and eventually the same code in Fortran). I rewote inner loops to hand optimize the compilation, and then recoded as SSE2. Finally, in a late night fit of sleeplessness, I rewrote the SSE2 as AVX to see what happens. I can’t exactly draw valid conclusions of these tests, but they were fun exercises.
Ok, now you know part of the history. Also, I’ve been playing more and more with javascript … no … node.js … for a set of projects. So I wanted to see how hard the port was from C to node. Well, not terribly hard. Remember, node.js uses the V8 engine as a compiler, and if you look at the Julia Language website with their scaled benchmark results, Javascript isn’t half bad relative to C.
And its actually not so bad to program in.
But back to the performance.
I rewrote rzf.c to rzf.js. If you want to run this you’ll need to run

npm install posix-getopt
npm install printf

and yes, I was being lazy with the conversion, printf almost works the way C’s does. I can clean up the code some what, but, this is a quick and dirty test, so don’t yell at me over the out=printf(…);console.log(out); sillyness.
Running the original rzf.c compiled with gcc

landman@pegasus:~/work/benchmarking/rzftest$ make -f Makefile.rzf-gcc
gcc -O3   -I. -Bstatic -c rzf.c
gcc -O3  -Bstatic -o rzf-gcc.exe rzf.o -lm
gcc -dA -dp -S -O3   -I. -Bstatic -c rzf.c -o rzf-gcc.s

I got this:

Read moreYou asked for it … Riemann Zeta Function in javascript or node.js


This past December, 1 year to the day, and in fact, the very hour my wife was waking up from her surgery, we were at a Trans Siberian Orchestra concert. I like TSO quite a bit, and this had serious significance for us. Like the XKCD biopsiversary, this was our own little F-U to cancer. … Read moreresonances

… and the positions are now, finally open …

See the Systems Engineering position here, and the System Build Technician position here. I’ll get these up on the site and a few others soon (tomorrow). But they are open now. For the Systems Engineering position, we really need someone in NYC area with a strong financial services background … Doug made me take … Read more… and the positions are now, finally open …

Massive. Unapologetic. Firepower. 24GB/s from siFlash

Oh yes we did. Oh yes. We did. This is the fastest storage box we are aware of, in market. This is so far outside of ram, and outside of OS and RAID level cache … [root@siFlash ~]# fio srt.fio … Run status group 0 (all jobs): READ: io=786432MB, aggrb=23971MB/s, minb=23971MB/s, maxb=23971MB/s, mint=32808msec, maxt=32808msec This … Read moreMassive. Unapologetic. Firepower. 24GB/s from siFlash

Precision in languages

I’ve talked about precision in previous posts quite a while ago. I had seen some interesting posts about Javascript, which suggested that it was not immune to the same issues … if anything it was as problematic as most other languages, and maybe had a little less “guarding” the programmer against potential failure modes.
This is not a terrible problem, I just found it amusing. Understand that I actually like Javascript. It does remind me in some ways of Perl and other tools I’ve used for writing code. Sadly it doesn’t seem to have Perl’s power for working with strings, parsing, etc. yet. Or mebbe I just don’t have the right libraries in mind. Doesn’t matter, v8 compiles it down to bloody fast code. Sadly, Perl6’s static compilation capabilities are lacking, and it is built upon the Parrot VM, so no matter how fast you can make Parrot, you still have a VM in the way, and you aren’t as close to bare silicon as you might like.
Several tweets pointed to interesting similar issues in other languages. Python, Lua, and Java.
So I decided to try Perl as well with the Python example.

my $a = 10000000000000000;
my $b = 10000000000000001;
printf "a = %i\n",$a;
printf "b = %i\n",$b;
printf " a == b is %s\n",( $a == $b ? "true" : "false");
my $c = 10000000000000000.0;
my $d = 10000000000000001.0;
printf "c = %s\n",$c;
printf "d = %s\n",$d;
printf " c == d is %s\n",( $c == $d ? "true" : "false");

Now try it

landman@pegasus:/tmp$ perl
a = 10000000000000000
b = 10000000000000001
 a == b is false
c = 1e+16
d = 1e+16
 c == d is true

Yeah. Same problem in Perl. How hard is it to work around (e.g. hide the real problem)?
Not hard at all. Use multiprecision libs by default

landman@pegasus:/tmp$ perl -Mbignum
a = 10000000000000000
b = 10000000000000001
 a == b is false
c = 10000000000000000
d = 10000000000000001
 c == d is false

Ignore the liberties the float to string conversion took in the second set of printf’s.
Yeah, this is an issue. Using multiprecision everywhere is slow, and could lead to some surprising memory usage for computational code. Its fairly obvious that the example was somewhat contrived as well … as to the relative precision of the numbers, the second comparison being true shouldn’t be a problem.
No, thats not what I found interesting. It was the missing integers example.

Read morePrecision in languages

Will the US default soon?

Quite possibly. We have a toxic mixture of overspending, insufficient revenue to cover the spending, and a borrowing limit. Several ideas have been floated over the last few weeks, including minting a $1T USD coin and depositing in the federal reserve. Thats $1012 USD folks. This is sort of like quantitative easing, aka printing more … Read moreWill the US default soon?

Game over, and thank you for playing

Remember this? Java is considered more secure than other languages for several reasons: The Java compiler catches more compile-time errors; other languages (like C++) will compile programs that produce unpredictable results. Java does not allocate direct pointers to memory. This makes it impossible to accidentally reference memory that belongs to other programs or the kernel. … Read moreGame over, and thank you for playing