time in Texas Hold'em

Discussion of Common Lisp
Post Reply
greenbeer
Posts: 3
Joined: Sun Apr 05, 2009 2:15 am

time in Texas Hold'em

Post by greenbeer » Fri Jul 10, 2009 2:47 am

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

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

Re: time in Texas Hold'em

Post by ramarren » Fri Jul 10, 2009 5:25 am

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.

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

Re: time in Texas Hold'em

Post by greenbeer » Fri Jul 10, 2009 12:11 pm

From this article http://norvig.com/python-lisp.html follows that CMUCL compiler is fast too.

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

Re: time in Texas Hold'em

Post by nuntius » Fri Jul 10, 2009 8:44 pm

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

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

Re: time in Texas Hold'em

Post by gugamilare » Sat Jul 11, 2009 1:26 pm

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.

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

Re: time in Texas Hold'em

Post by Ben » Mon Jul 13, 2009 7:32 am

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

You could try this for example.

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

Re: time in Texas Hold'em

Post by szergling » Wed Jul 22, 2009 1:08 am

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).

Post Reply