From: David Pollak Date: 2006-07-27T00:42:46+09:00 Subject: Re: For performance, write it in C Writing code that runs as fast in Java as it does in C is real work, but it's possible. Integer (http://athena.com) is a pure Java spreadsheet. I optimized the numeric functions and array functions (e.g., SUM(A1:G99)) such that Integer runs as fast or faster than Excel and OpenOffice Calc on identical hardware. However, it required a mind shift from "standard" Java programming. In addition, because Java has nice semantics for multithreading, I was able to implement some very cleaver algorithms such that Integer's recalculation speed scales nearly linearly with additional CPUs up to a certain point (the linearity goes away at around 16 processors on a big Sun box.) But I digress. First, I pre-allocated a lot of workspace so that there's little memory allocation going on during recalculation. Second, I avoid Monitors (synchronized) as much as possible. Third, I write "C" style Java (lots of switch statements, putting parameters and results in buffers rather than passing them on the stack, etc.) Memory usage in Java is higher than in C. If Java has Structs a la C#/Mono, it'd be possible to squeeze that much more performance from Java. There are some applications that will never perform as in Java (e.g., stuff that's heavily oriented to bit manipulation.) But for many classes of applications (e.g., spreadsheets) Java can perform as well as C. When I care about computational performance, I go with Java or in a rare case, C++ (C style C++, no STL or virtual methods). If I care about developer performance, I've been going with Ruby more and more. My 2 cents. On 7/26/06, James Edward Gray II wrote: > On Jul 26, 2006, at 8:57 AM, Charles O Nutter wrote: > > > - Write it in C is as valid as write it in Java (as someone else > > mentioned). > > Java is at least as fast as C for most algorithms. > > I'm Java Certified and I've been hearing people say this for years, > but I just haven't experienced this myself. You guys must develop on > much faster boxes than my MacBook Pro. ;) > > James Edward Gray II > > > -- -------- David Pollak's Ruby Playground http://dppruby.com