Page 1 of 1

time in Texas Hold'em

PostPosted: Fri Jul 10, 2009 2:47 am
by greenbeer
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

Re: time in Texas Hold'em

PostPosted: Fri Jul 10, 2009 5:25 am
by Ramarren
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.

Re: time in Texas Hold'em

PostPosted: Fri Jul 10, 2009 12:11 pm
by greenbeer
From this article http://norvig.com/python-lisp.html follows that CMUCL compiler is fast too.

Re: time in Texas Hold'em

PostPosted: Fri Jul 10, 2009 8:44 pm
by nuntius
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

Re: time in Texas Hold'em

PostPosted: Sat Jul 11, 2009 1:26 pm
by gugamilare
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.

Re: time in Texas Hold'em

PostPosted: Mon Jul 13, 2009 7:32 am
by Ben
Maybe you want to investigate your program with a metering/profiling-tool to optimize your code.

You could try this for example.

Re: time in Texas Hold'em

PostPosted: Wed Jul 22, 2009 1:08 am
by szergling
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).