Author Topic: Check this please  (Read 9956 times)

0 Members and 1 Guest are viewing this topic.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: Check this please
« Reply #15 on: November 11, 2008, 03:39:28 pm »
Now i've finished it and Java runs about 70% faster then the C.

Really? Using -O2?

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline nslay

  • Hero Member
  • *****
  • Posts: 786
  • Giraffe meat, mmm
    • View Profile
Re: Check this please
« Reply #16 on: November 20, 2008, 12:41:03 am »
Java does have JIT which supposedly generates some native code at run time.  However, I find it hard to believe a highly suggestive and properly structured C code would underperform a Java code.  Please compare your C code with a real compiler (e.g. icc). GCC is utter garbage when it comes to performance.  Also, take advantage of C99 features (e.g. inline and restrict).  Be as suggestive to the compiler as you can (e.g. use register qualifier where appropriate, order code to make vectorization more obvious..."neatness" and "style" have no meaning!).  Also order your C code to mix as many operations as possible to reduce register pressure (compiler can generally do this).  Finally, JIT probably takes advantage of processor-specific features (e.g. SSE for vectorization), please turn these features on when compiling the C code.
Why do you have to do this in C?  Because C is complicated!  The compiler cannot make too many assumptions.  If you can, code the same program in Fortran and use ifort (again, GCC blows!).  Fortran will probably blow both Java and C away because the language is so simple, the compiler can make more aggressive optimizations.
An adorable giant isopod!

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: Check this please
« Reply #17 on: November 20, 2008, 01:16:34 am »
why stop at fortran? assembly is what performance pros use

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Check this please
« Reply #18 on: November 20, 2008, 01:48:33 am »
"neatness" and "style" have no meaning!

lol

Offline nslay

  • Hero Member
  • *****
  • Posts: 786
  • Giraffe meat, mmm
    • View Profile
Re: Check this please
« Reply #19 on: November 20, 2008, 11:14:12 am »
why stop at fortran? assembly is what performance pros use
Sometimes, but rarely.  You have to know all sorts of details about the processor and machine in order to produce high performance applications in assembler.  So, performance pros don't often use assembler.  There are a few exceptions, as an example: my friend does numerical linear algebra and works on a cluster of PS3s here, the current C/Fortran compilers for Cell cannot take full advantage of the Cell's vector capabilities (i.e. BLAS and LAPACK would suck!).  As a consequence, he wrote some common vector routines in assembler.  Almost nobody writes extensive high performance applications in assembler...its not portable and a human often does a worse job than a compiler.
You know whats sad?  Fortran is crazy simple and it is the language of choice for many high performance numerical codes...written by people older than us with less knowledge about the computer.  You have to know a good deal about what you're doing to do anything high performance in Assembler or C.  Actually, despite my dislike of C++...C++'s templates, inline functions, and reference types (similar to restrict pointers) makes it easier for a C++ application to even outperform a C equivalent!

EDIT: P.S. And with regards to your comment, C is actually lower level than Fortran.  It would have been more appropriate to say "Why stop at C?".
« Last Edit: November 20, 2008, 11:17:52 am by nslay »
An adorable giant isopod!

Offline Chavo

  • x86
  • Hero Member
  • *****
  • Posts: 2219
  • no u
    • View Profile
    • Chavoland
Re: Check this please
« Reply #20 on: November 20, 2008, 11:43:55 am »
My comment was not designed to be a serious suggestion as much as a joking comment regarding the silliness of even having the discussion.

Offline Hdx

  • The Hdx!
  • Full Member
  • ***
  • Posts: 311
  • <3 Java/Cpp/VB/QB
    • View Profile
Re: Check this please
« Reply #21 on: November 20, 2008, 12:00:30 pm »
The main reason I chose C was because I wanted to become more fluent in it. My code right now is by no means optimized/efficient. JBLS uses ~56mbs of memory just idling, and 3/4ths the damn thing isnt even written yet! But, what I figure is i'll optimize things after i get the bulk of it working. There is no release date this is purly for my own enjoyment.

I plan to in the future teach myself other languages Fortran included. But I figured C was a good place to start.
http://img140.exs.cx/img140/6720/hdxnew6lb.gif
09/08/05 - Clan SBs @ USEast
 [19:59:04.000] <DeadHelp> We don't like customers.
 [19:59:05.922] <DeadHelp> They're assholes
 [19:59:08.094] <DeadHelp> And they're never right.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Check this please
« Reply #22 on: November 20, 2008, 01:33:28 pm »
The main reason I chose C was because I wanted to become more fluent in it. My code right now is by no means optimized/efficient. JBLS uses ~56mbs of memory just idling, and 3/4ths the damn thing isnt even written yet! But, what I figure is i'll optimize things after i get the bulk of it working. There is no release date this is purly for my own enjoyment.

I plan to in the future teach myself other languages Fortran included. But I figured C was a good place to start.

Are we talking about Java Battle.net Login Server or Just Another Battle.net Login Server?
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Hdx

  • The Hdx!
  • Full Member
  • ***
  • Posts: 311
  • <3 Java/Cpp/VB/QB
    • View Profile
Re: Check this please
« Reply #23 on: November 20, 2008, 02:01:14 pm »
Java uses like 90 with everything loaded.
C uses 56
http://img140.exs.cx/img140/6720/hdxnew6lb.gif
09/08/05 - Clan SBs @ USEast
 [19:59:04.000] <DeadHelp> We don't like customers.
 [19:59:05.922] <DeadHelp> They're assholes
 [19:59:08.094] <DeadHelp> And they're never right.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: Check this please
« Reply #24 on: November 20, 2008, 02:21:07 pm »
Java does have JIT which supposedly generates some native code at run time.  However, I find it hard to believe a highly suggestive and properly structured C code would underperform a Java code.  Please compare your C code with a real compiler (e.g. icc). GCC is utter garbage when it comes to performance.  Also, take advantage of C99 features (e.g. inline and restrict).  Be as suggestive to the compiler as you can (e.g. use register qualifier where appropriate, order code to make vectorization more obvious..."neatness" and "style" have no meaning!).  Also order your C code to mix as many operations as possible to reduce register pressure (compiler can generally do this).  Finally, JIT probably takes advantage of processor-specific features (e.g. SSE for vectorization), please turn these features on when compiling the C code.
Why do you have to do this in C?  Because C is complicated!  The compiler cannot make too many assumptions.  If you can, code the same program in Fortran and use ifort (again, GCC blows!).  Fortran will probably blow both Java and C away because the language is so simple, the compiler can make more aggressive optimizations.

Hotspot does not do much optimization; what's the point of having code that executes fast if it takes five minutes to JIT compile? Hotspot does have the advantage of already having the bytecode instructions, which are much easierquicker to translate in to machine code than C source, but it is none the less a non-trivial operation, thereby limiting the jitter's ability to consider optimizations. If a block of code is observed to be used very often, Hotspot may bring it up as a candidate for further optimization. However, for a test like this, GCC with -O2 should beat Hotspot-enhanced Java every time.
« Last Edit: November 20, 2008, 02:25:30 pm by Camel »

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!