This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Kawa function micro benchmarks
- From: Chris Dean <Chris dot Dean at sokitomi dot com>
- To: Kawa List <kawa at sources dot redhat dot com>
- Date: Thu, 31 Jul 2003 20:55:11 -0700
- Subject: Kawa function micro benchmarks
I did some simple benchmarks to see how fast Kawa was at calling
functions. No conclusions, just wanted to share the numbers.
There are three tests of interest:
1. Calling a function defined within the local module.
2. Calling a simple lambda function defined within the local module.
3. Calling a function defined within a remote module. The remote
function was imported using the require form.
Calling these functions 5,000,000,000 times gives:
local total: 0.83 secs per call: 0.17 ns
lambda total: 24.37 secs per call: 4.87 ns
remote total: 24.45 secs per call: 4.89 ns
That is, calling the locally defined function N times took 0.83 seconds.
Each individual call therefore took 0.17 nanoseconds.
As you may know, Kawa compiles local calls down to invoking a static
method - very fast. Both the lambda and remote test go through a more
sophisticated interface that call Java "virtual" methods - in this test
about 30 times slower.
All tests were run on a lightly loaded Debian Linux box using Sun Java
1.4.1_01 with the server JIT turned on and the CVS version of Kawa as of
this date. This box is a PC with dual Xeon 2.40GHz CPUs (a Dell
PowerEdge 2650).
The code I used is below, but it won't compile without some internal
libraries. Send me an email if you'd like a copy of these libraries.
Regards,
Chris Dean
(module-name <FuncCallTime>)
(require <com.merced.util.scheme.Compat>)
(require <com.merced.util.scheme.TimeDate>)
(require <Remote>)
(define *N* (* 5 1000 1000 1000))
(define (call-with-time fn)
(exact->inexact
(time->number
(let ((start (current-time)))
(fn)
(time-difference (current-time) start)))))
(define (local)
'ok)
(define (test-local)
(dotimes (i *N*)
(local)))
(define (test-lambda)
(test-lambda-aux (lambda () 'ok)))
(define (test-lambda-aux fn)
(dotimes (i *N*)
(fn)))
(define (test-remote)
(dotimes (i *N*)
(remote)))
(define-namespace proc "class:gnu.mapping.Procedure")
(define (test-newstyle-remote)
(let ((mf (make <ModuleFunction>)))
(dotimes (i *N*)
(proc:apply0 mf))))
(define-namespace module-function "class:ModuleFunction")
(define (test-newstyle-remote-static)
(let ((mf (make <ModuleFunction>)))
(dotimes (i *N*)
(module-function:new-remote))))
(define (dump tag val)
(format #t "~16S total: ~6,2F secs per call: ~6,2F ns~%" tag val
(* 1000 1000 1000 (/ val *N*))))
(dump 'local (call-with-time test-local))
(dump 'lambda (call-with-time test-lambda))
(dump 'remote (call-with-time test-remote))
(dump 'new-remote (call-with-time test-newstyle-remote))
(dump 'new-static (call-with-time test-newstyle-remote-static))
;; local total: 0.83 secs per call: 0.17 ns
;; lambda total: 24.37 secs per call: 4.87 ns
;; remote total: 24.45 secs per call: 4.89 ns
;; new-remote total: 20.47 secs per call: 4.09 ns
;; new-static total: 0.83 secs per call: 0.17 ns