Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

CL benchmarking

Name: Anonymous 2014-10-12 6:59

Is there a free benchmarking library for Common Lisp? Something like Haskell's Criterion, perhaps?

Name: Anonymous 2014-10-18 18:55

>>13
Normally you wouldn't be able to trigger me into doing this, but I haven't written lisp in a while and this time it was fun.

(defpackage #:bench-mark
(:use #:cl)
(:export #:hello))

(in-package #:bench-mark)

(defun hello ()
(print "hello"))

(defvar bench-log nil)
(defvar kw-call "call")
(defvar kw-return "return")

(defun clear-bench-log ()
(setq bench-log nil))

(defun append-bench-log (ent)
(push ent bench-log))

(defun function-called (name time)
(append-bench-log (list kw-call name time)))

(defun function-returned (name time)
(append-bench-log (list kw-return name time)))

(defun profile-test1 (x)
(let (ret)
(function-called 'profile-test1 (get-internal-real-time))
(setq ret (loop for i from 1 to x sum i))
(function-returned 'profile-test1 (get-internal-real-time))
ret))

(defmacro profiled-body (name &rest body)
(let ((ret-sym (gensym)))
`(let (,ret-sym)
(function-called ,name (get-internal-real-time))
(setq ,ret-sym (progn ,@body))
(function-returned ,name (get-internal-real-time))
,ret-sym)))

(defun profile-test2 (x)
(profiled-body 'profile-test2
(loop for i from 1 to x sum i)))

(defmacro defun-prof (name args &rest body)
`(defun ,name ,args
(profiled-body ',name
,@body)))

(defmacro defmethod-prof (name args &rest body)
`(defmethod ,name ,args
(profiled-body ',name
,@body)))

(defmacro lambda-prof (name args &rest body)
`(lambda ,args
(profiled-body ',name
,@body)))

(defun-prof profile-test3 (x)
(loop for i from 1 to x sum i))

(defmethod-prof profile-test4 ((x integer))
(loop for i from 1 to x sum i))

(defun profile-test5 (x)
(funcall (lambda-prof profile-test5 (x)
(loop for i from 1 to x sum i))
x))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List