Image Image Image




Post new topic Reply to topic  [ 86 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject: Re: Yet Another Language War
PostPosted: Tue Sep 22, 2009 11:43 pm 
Offline
Senior member
User avatar

Posts: 120
Favourite Bot: mine, in writing
So I implemented a correlation calculation on a matrix big enough to have the program run for some time.
My code is simple code, not parallelized (even though it's running on a multi-core CPU).

Code:
# vi cr.c
# vi cr.java
# gcc -lm -O3 -mtune=native -mfpmath=sse -msse2 cr.c -o cr
# javac cr.java
# time ./cr
29.8u 0.0s 0:29.85 100.0% 0+0k 0+0io 0pf+0w
# time java Cr
34.4u 12.8s 0:25.74 183.5% 0+0k 0+64io 1pf+0w


What do those result mean?


If I had used a hand chrono, Java would have finished 4.1s earlier than C (=29.85-25.74, as here I'm comparing real times).

Now the time that counts is the total CPU time, given by adding user and sys. Here, C beats Java by a wide margin: 29.8s vs 37.2s (adding 29.8+0 and 34.4+12.8).

=> Java takes roughly 25% more CPU time than C
=> Java beats C to the finish line (13% faster) as a significant portion of my code was in system time (using another core(s), hence the 183.5%).

So C is faster but slower. And Java is slower but faster. I guess that makes everyone happy.

more info on real user and system times:
http://www.ncsa.illinois.edu/UserInfo/R ... 365c62.htm


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 8:02 am 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
Heh.

Can you attach the source code of what you tested? I would be curious to compile with JDK 6 and VS 2005/2008 and compare ...

I think you can google a lot of studies that show one or the other is faster, such discussion never ends, just in the last several years it simply ignored by most people (exception in occasions like this one :)

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 10:54 am 
Offline
Junior member
User avatar

Posts: 18
Favourite Bot: Min
I would expect a lot of it to come down to compiler effiency.

If you want fast code learn and use assembly, however I think most decent compilers arent too far off.

I would suspect for most people spending time on algorithm optimisation would be first priority.

Personally im a big fan of c and its variants, but still horses for courses.

Jim


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 3:17 pm 
Offline
Senior member
User avatar

Posts: 120
Favourite Bot: mine, in writing
Also FYI


# java -version
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) 64-Bit Server VM (build 14.2-b01, mixed mode)
# gcc --version
gcc (Debian 4.3.4-2) 4.3.4
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 3:32 pm 
Offline
Senior member
User avatar

Posts: 120
Favourite Bot: mine, in writing
Indiana I sent you my code by PM.

You'll note that:
- it's not exactly doing correlation, but both C and Java perform the same calculations
- it's not drawing random numbers but deterministic ones (as I didn't want to have to include that other factor)
- it is not optimized (some variables are created and deleted and re-created), but both Java and C have the same instructions


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 3:46 pm 
Offline
Senior member
User avatar

Posts: 120
Favourite Bot: mine, in writing
indiana wrote:
Heh.

Can you attach the source code of what you tested? I would be curious to compile with JDK 6 and VS 2005/2008 and compare ...

I think you can google a lot of studies that show one or the other is faster, such discussion never ends, just in the last several years it simply ignored by most people (exception in occasions like this one :)



You are certainly right.
I would be surprised if absolutely every single portion of code was faster in C than Java.
So you could always come up with examples that prove different points (although “prove” is not the right word here, since an example has never been a proof).

To go back to the original topic of this thread: yes, I expect an average or rather inexperienced programmer to develop a bot much faster in Java/C# than in C/C++.
However, I expect that an expert programmer in C/C++ would come up with a faster bot than an expert programmer in Java/C#. And by expert I mean “guy who knows every single thing there is to know about a language”. Why do I expect that? Because C/C++ allows you to have more control, hence you can make sure that not a single unnecessary instruction is run (in theory). Which you cannot do in VM/framework/managed environments. This is a theoretical discussion, and of course not a single complex implementation will be perfectly optimized (at least at our level) so this may be irrelevant.


Note: I don’t consider myself an expert programmer at all. I’m most likely only average or probably below.


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 4:49 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
I'll check out the examples just out of curiousity.

sob wrote:
To go back to the original topic of this thread: yes, I expect an average or rather inexperienced programmer to develop a bot much faster in Java/C# than in C/C++. However, I expect that an expert programmer in C/C++ would come up with a faster bot than an expert programmer in Java/C#. And by expert I mean “guy who knows every single thing there is to know about a language”.


I kind of disagree here. I think being faster with some percentages is totally ignorable thing for the scope of botting. Currently I can run almost as many tables as I want on my PC (say 100), and am pretty much bound by number VMs and the pokersite resource consumption and memory. Of course you can code crappy bot in any language, I don't think the speed comes from the language in almost any problem you can think of (except very specific ones) nowadays (and this is only if you assume C++ is faster than Java anyway).

Other things (like code maintainability, portability and compatibility, ease of development, etc.) is much much much more important IMO - for proffesional programmers and large codebases as much as for intermediate one. And Java/C# is better in that.

So the original topic was not which language is faster (this was only raised as argument for C++, and btw there is quite big difference in many aspects if you code in C or C++ so I don't know why you slash them above. I thinking slashing Java and C# is appropriate, but slashing C and C++ is not, as coding object oriented is completely different thing). The original topic was which language would you recommend for development of a bot, where my one would be Java.

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 5:23 pm 
Offline
Senior member
User avatar

Posts: 120
Favourite Bot: mine, in writing
I slash C and C++ since their output is a binary that runs directly on the machine.
Java(c) produces a semi-binary that runs on a virtual machine.


For the points you made:

- AI engine resources consumption is going to be negligible compared to (your) VMs and client: probably. But that’s because you have a bot already. I am starting one myself, and I have to face this choice of the language. Not knowing exactly where my biggest slowdowns would be, I wanted to prepare for the worst, and at least make sure my scraping / ocr if any / AI would not be the limiting factor. Was I being too cautious? Probably. Again, going back to that 7 card hand eval thread, IIRC there was a user who claimed a C (or C++?) implementation of the #1 (Java) that was what… 2x? 3x? 4x faster? Hand eval / MC simulations is something a bot is going to end up doing a lot. And even if the precision required needn’t be up to the 5th decimal, I wouldn’t want to make the assumption that “having a relatively slow algorithm” or “using a slower language like perl” (note: I absolutely love Perl when it comes to scripting) would be “good enough”.

- Java/C# are more easily maintainable than C. Ok. Most certainly. And probably regardless of you level. Than C++? To the un-experienced programmer? Absolutely 100% correct. For the average? Not sure. For the experience? Even less sure.

Now I can’t seem to find the original thread where that person asked which language to use.

However, if the person asks this, then he’s probably (very) unexperienced. And in that case he should definitely go not for language A because it’s better for reasons X and Y, but for language B if language B is the language he masters the most.
I wouldn’t recommend Java if the user knew Perl only. I wouldn’t recommend Java if the user knew C only. I wouldn’t recommend C++ if the user knew C only. I wouldn’t recommend C++ if the user knew Java only.

Now in his specific case, there’s a 99% likelihood your advice to go with Java was “the right thing to tell him”.
BUT seeing “Java is better than C” for purpose P1 or purpose P2 is something I had to jump on :)











Any luck with my examples? :D





Now I have 2 ideas for 2 new threads (not sure if I’ll post new threads as I don’t want to start unnecessary discussions):
- Anyone botting under Linux? What difficulties do you have to overcome that you wouldn’t see under Windows? What benefits do you see using Linux?
- What’s the bottleneck in your system? VMs? Clients? Bot scraping/ocr? Bot AI? Regardless of whether your bot is the bottleneck, did you run a profiling tool on your code to see where you spent most time? What are the results and breakdowns of time spent?


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 8:57 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
sob wrote:
I slash C and C++ since their output is a binary that runs directly on the machine.
Java(c) produces a semi-binary that runs on a virtual machine.

Java as well is pretty much a binary, but it's compiled at runtime. No big diff. here.

For the points you made:

sob wrote:
But that’s because you have a bot already.

I said that if I'm gonn start over, I will again start over in Java.

sob wrote:
Again, going back to that 7 card hand eval thread, IIRC there was a user who claimed a C (or C++?)

It was C, and it was with special optimizaitons (which were never tried in the Java impl, as it was already faster than anything you would need for any reason). I don't know why you are still assuming C++ is faster than Java. There are many examples where Java has been shown faster, and thre are many (maybe many more) where C++ has been faster, but this is never in the range of 20% or more. If you build a bot, either 20% performance is compeltely ignorable (in either direction) or you face a problem where you have to optimize things and make them 1,000,000 times or 10^20 faster, not 20% faster.

sob wrote:
Java/C# are more easily maintainable than C. Ok. Most certainly. And probably regardless of you level. Than C++? To the un-experienced programmer? Absolutely 100% correct. For the average? Not sure. For the experience? Even less sure.

For experience programmers - too. If you are profficient in C++, you are still less productive over a large codebase than a profficient programer in Java.

sob wrote:
Now in his specific case, there’s a 99% likelihood your advice to go with Java was “the right thing to tell him”.
BUT seeing “Java is better than C” for purpose P1 or purpose P2 is something I had to jump on :)

Well, if I have to restart all I did again - I would still do it in Java, not in C++. Hence, IMO, it's better. Language attribute for very small tiny part of being successfull, thou.

sob wrote:
Anyone botting under Linux? What difficulties do you have to overcome that you wouldn’t see under Windows? What benefits do you see using Linux?

Lol not another Lunix vs Windows thread pls :)

P.S. Sticking to Windows is clearly better and what I would recommend :)

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 9:30 pm 
Offline
Senior member
User avatar

Posts: 120
Favourite Bot: mine, in writing
My point was that you know that your Java bot works in terms of speed and capabilities, so of course you can say it's better, and of course you would use Java again if you were to start over. Now if you had no language preference and were working from scratch (as I was a month ago) it'd be a different thing. And going for an implementation that you think (even if untrue, I don't want to use "know" here because I'm not proselytizing any technology) is faster by a significant margin (again, think, not know) would make sense. Now I have not much more to say on that topic, unless someone is interested in technical discussions with specific examples as I provided, and potentially explanations as to why one is faster than the other. Even if it's not representative of what a bot would do. Btw Indiana on the example I sent you earlier the C CPU time is 91.2s vs 164.1s for Java (i.e. Java 80% slower). If you see something I have missed that would explain this difference I would gladly learn, as, again, I am not an expert in any of the two languages.

I was more thinking of a thread where people botting under Linux (as I am) could exchange ideas for Linux specific issues (running clients with Wine, using QEMU/KVM virtualization, using Xlib or XCB, etc). I'm not trying to move people away from Java or Windows, don't worry ;) And I've already made my technical choices.


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 9:48 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
sob wrote:
My point was that you know that your Java bot works in terms of speed and capabilities, so of course you can say it's better, and of course you would use Java again if you were to start over. Now if you had no language preference and were working from scratch (as I was a month ago) it'd be a different thing.

I am pretty profficient in C, C++, Java, and C#. So it's not that I'm used to Java, to recommend it. I simply don't use C++ any longer, as I see no point in doing that (I speak for botting amongst other things, there are still some cases where I might use C++). Otherwise I had developed a huge amounts of code in C++ in the past.

sob wrote:
I was more thinking of a thread where people botting under Linux (as I am) could exchange ideas for Linux specific issues (running clients with Wine, using QEMU/KVM virtualization, using Xlib or XCB, etc). I'm not trying to move people away from Java or Windows, don't worry ;) And I've already made my technical choices.

I certainly wouldn't mind such thread (Would be good). My advice would be to not use Linux, but here I wouldn't even claim of being an expert in all the things one can achieve under Linux (although I right away can think of some issues with that approach). But I don't think I even got your proposal - does it involve running Windows VMware, or it's all Linux? Anyway, feel free to go ahead with such thread would be good IMO ...

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 9:54 pm 
Offline
Senior member
User avatar

Posts: 120
Favourite Bot: mine, in writing
Well it's very likely you have more experience than me in both Java and C then. If you can explain the results I get in terms of speed, I'd love to learn. Did you try my code with your JVM and VS2008?



All Linux. If virtualization is needed, KVM proves to be much more efficient in terms of resources than VMWare (seriously, I was blown away).

I’m curious to know the issues you see running Linux. Could you name a few (in PM if you’d like).

Actually I’ll start the Linux botting thread. When my bot is complete. Unless someone beats me to it.


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 10:04 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
sob wrote:
I’m curious to know the issues you see running Linux. Could you name a few (in PM if you’d like).
Actually I’ll start the Linux botting thread. When my bot is complete. Unless someone beats me to it.

I will PM you later.

btw, just curious, what is the redpill output under KVM?
Attachment:
redpill.rar [11.59 KB]
Downloaded 66 times

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 10:28 pm 
Offline
Senior member
User avatar

Posts: 120
Favourite Bot: mine, in writing
What do you want the guest OS to be? Windows? Linux?


(Windows I assume, as that code segfaults on the Linux host)


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Wed Sep 23, 2009 11:01 pm 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
Yes, windows.

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Thu Sep 24, 2009 12:33 am 
Offline
Senior member
User avatar

Posts: 120
Favourite Bot: mine, in writing
Not in Matrix


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Thu Sep 24, 2009 12:39 am 
Offline
Senior member
User avatar

Posts: 360
Favourite Bot: Zander
sob wrote:
Actually I’ll start the Linux botting thread. When my bot is complete. Unless someone beats me to it.

I started a thread several months ago regarding botting under Linux and basically got flamed for being "different". I chose to bot a site that offers a Flash client via packet sniffing. For anything VM related, i use VirtualBox.

_________________
http://www.bespokebots.com


Top
 Profile  
 
 Post subject: Re: Yet Another Language War
PostPosted: Thu Sep 24, 2009 7:52 am 
Offline
PokerAI fellow
User avatar

Posts: 7731
Favourite Bot: V12
birchy wrote:
I started a thread several months ago regarding botting under Linux and basically got flamed for being "different".

Well, you guess the biggest issue of being different is not the potential flames on any forum, but the flags this would raise :)
If you know really well what you are doing (in Linux environment) I don't think there would be some huge showstopers in comparison to windows (except site support, when you do use linux guests). I don't know however, there are normally 1000s of things that can go wrong, and until you chck them out, you never know.

_________________
indiana


Top
 Profile E-mail  
 
 Post subject: Re: Yet Another Language War
PostPosted: Thu Sep 24, 2009 10:30 am 
Offline
Senior member
User avatar

Posts: 360
Favourite Bot: Zander
Linux is becoming quite common for desktop users nowadays, especially with distributions like Ubuntu. My main reason for choosing linux was the reliability. You don't need to install some big fat security suite and it's quite common for linux servers to run for several YEARS at a time without being rebooted. And, of course, all the software (and source code) is free. I guess it all boils down to personal preference.

_________________
http://www.bespokebots.com


Top
 Profile  
 
 Post subject: Re: Yet Another Language War
PostPosted: Thu Sep 24, 2009 12:59 pm 
Offline
Senior member
User avatar

Posts: 458
Location: Now in the mighty PolarBoar variant!
Favourite Bot: ...
birchy wrote:
Linux is becoming quite common for desktop users nowadays.


I wouldn't call a market share of about 1% quite common (BTW we need an emoticon of guy with a flame thrower just for occasions like this ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 86 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: