[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] A more detailed plea for help with FFI...

From: Ed Watkeys
Subject: Re: [Chicken-users] A more detailed plea for help with FFI...
Date: Wed, 15 Dec 2004 14:47:35 -0500

On Dec 15, 2004, at 12:44 PM, Ed Watkeys wrote:

As soon as I get back from lunch, I'll write a couple programs that create and destroy a million native chicken-string and foreign-string instances and compare the run times.

Running the code below with the set-finalizer! call in 1) place and 2) commented out resulted in a runtime delta of about eight seconds on my 1.33 GHz PB G4 12" running OS X 10.3.6. That means that the overhead of handling a finalizer call is about 80 microseconds, or about 0.00008 seconds. That's about 110,000 processor cycles. Wow.


;;; code below

#include "string.h"
#include "assert.h"

static void *make_a_string_c(void) {
  const len = 16; char *s = malloc(len); int i = 0;
  assert(s != NULL);
  for(; i < len-1; i++) s[i] = 'a' + i;
  s[i] = '\0';
  return s;

static void free_a_string_c(void *s) {
  if(s) free(s);

(define make-a-string
  (lambda ()
    (let ((s (make_a_string_c)))
      (set-finalizer! s free_a_string_c)

      (lambda (n)
        (cond ((= n 0) #t)
              (else (make-a-string)
                    (loop (- n 1)))))))
  (loop 100000))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]