time in Texas Hold'em

Discussion of Common Lisp

time in Texas Hold'em

I wrote Texas Hold'em calculator in cl.
(This program in cl is of course open source, not commerial )
It goes good but there is a big time difference of evaluation in sbcl and clisp.
For example:
when we have hand: Jack of Diamonds and Queen of Diamonds
and there is three hidden opponents:

i get in sbcl:
(34.66 2.4490001) (odds for win and odds for drawn)
time: 1.946 seconds of real time

and in clisp:
(34.643 2.5319998)
time: Real time: 67.22213 sec.

Small diferences in evaluation are result from randomness in algorithm.
(I used 100000 repetitions in drawing cards from deck)

I give a part of my program with function "test" which checks validation of random choice community cards form deck:

Code: Select all
(defmacro rm-it (i a len)
`(setf (aref ,a ,i) (aref ,a (decf ,len))))

(defun rand-ch (n a len)
(let ((i) (res) (items))
(loop repeat n do
(setf i (random len))
(push (aref a i) res)
(push i items)
(rm-it i a len))
(list res items)))

(defun make-deck ()
(let ((a (make-array 52)))
(loop for i upto 51 do (setf (aref a i) i)) a))

(defmacro rm-hand (hand stack len)
`(progn
(rm-it (position (car ,hand) ,stack) ,stack ,len)
(rm-it (position (cadr ,hand) ,stack) ,stack ,len)))

(defun clean-deck (deck removes)
(destructuring-bind (rm-cards rm-items) removes
(loop for c in rm-cards for i in rm-items do
(setf (aref deck i) c))))

(defun test (n)
(let ((deck (make-deck)) (choice) (cards) (len 52) (rep t))
(rm-hand '(23 40) deck len)
(loop repeat n  while rep do
(setf choice (rand-ch 5 deck len))
(setf cards (car choice))
(when (/= (length (remove-duplicates cards)) 5)
(print cards) (setf rep nil))
(clean-deck deck choice))))

And i've got:
(time (test 100000)):
sbcl: 0.659 sec
clisp: 8.258135 sec

From what such big time difference in these two cl implementations? What can I change in program?
I'm always using sbcl, but I want to show this program on ms windows also. ,

thanks
greenbeer

Posts: 3
Joined: Sun Apr 05, 2009 2:15 am

Re: time in Texas Hold'em

greenbeer wrote:From what such big time difference in these two cl implementations? What can I change in program?
I'm always using sbcl, but I want to show this program on ms windows also. ,

SBCL has an optimizing compiler, emitting native machine code, and CLisp has a bytecode interpreter. I think I saw some talk about JIT compiler for CLisp, but I don't know how this works, and in any case I doubt it will have as good results as Lisp-specific compiler SBCL uses.

Note that SBCL has a Windows port, which works most of the time, so you can try that.
ramarren

Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: time in Texas Hold'em

greenbeer

Posts: 3
Joined: Sun Apr 05, 2009 2:15 am

Re: time in Texas Hold'em

As Ramarren said, you might not be able to get more performance out of clisp.

But there are many other implementations on windows. See http://common-lisp.net/~dlw/LispSurvey.html

nuntius

Posts: 535
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: time in Texas Hold'em

nuntius wrote:As Ramarren said, you might not be able to get more performance out of clisp.

But there are many other implementations on windows. See http://common-lisp.net/~dlw/LispSurvey.html

This webpage doesn't say that Clozure CL now have an implementation for Windows. Clozure is very fast either (according to cl-bench), although it does not have the very powerfull type inference SBCL has. It also looks like that CCL in windows is not "alpha" (I didn't test it, though), and it is an implementation with a very good quality.

I don't believe you will be able to speed up clisp very much, speed is not one of this implementation's concern, although it is a very good (and widely used) implementation.
gugamilare

Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil

Re: time in Texas Hold'em

Maybe you want to investigate your program with a metering/profiling-tool to optimize your code.

You could try this for example.
Ben

Posts: 6
Joined: Thu Jul 02, 2009 2:28 am
Location: Germany

Re: time in Texas Hold'em

Additionally, I've often managed to speed up code by about 2 to 3 times (if I'm lucky) by compiling the clisp function. If you run your code interpreted, there's a performance hit, but I'm not sure how much these days (clisp has a JIT, the last I hear).
szergling

Posts: 2
Joined: Wed Jul 22, 2009 1:02 am