From: jcb@... (MetalOne) Date: 2002-11-22T03:56:18+09:00 Subject: Re: Ruby is too slow "Bulat Ziganshin" wrote in message news:<36275642663.20021121125533@integ.ru>... > Hello Peter, > > Thursday, November 21, 2002, 12:31:04 PM, you wrote: > > >> it is because ruby interpreted language, while java and c++ are > >> compiled to machine code. this sort of tasks definitely not for > >> ruby > > PH> Java compiles to byte code that is then interpreted. > > .. or compiled using JIT. based on timings in original post, i think, > his code is compiled The Jave code was compiled using Sun JDK 1.4 for Win32, which uses their hotspot technology. I think that is just their latest name for JIT. I didn't test timings, but the C++/Java comparisons I did were not exactly fair. I knew the C++ could compile more efficiently. At least without clever optimization. C++, *imageIt = lookup[*imageIt]; imageIt++ Java, image[i] = lookup[image[i]]; i++; I also recognize that Ruby is interpreted. However, I did not expect the factor of 200 difference. The interpreter only needs to parse the loop once, it should then have byte code to execute for each iteration. Of course, it must translate the byte code to machine code, for execution. I would have expected some constant overhead for this translation on the order of 2 or 3 times. This is a very tight loop though and every extra op makes a significant difference. I knew Ruby was not up for my current task. That is why it is being written in C++. I was just curious at close it could come. I was really blown away, by exactly how inadequate it is at such things. However, Ruby blocks are really nice. I have been trying to make my C++ do the same thing and I just end up with this mess. template void map(FuncData &data, T &v) { v = data.lookup[v]; } template void for_each_pixel(ImageData &id, FuncData &fd, void (*func)(FuncDataOnly &fdo, T &v) ) { T *imageIt = id.image; T *pLast = imageIt + id.imageSize; while (imageIt != pLast) { (*func)(fd, *imageIt); imageIt++; } }