guile-devel
[Top][All Lists]
Advanced

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

Re: data-crunching in guile


From: Andy Wingo
Subject: Re: data-crunching in guile
Date: Fri, 26 Jun 2009 14:09:16 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux)

Hi,

I've gone ahead and added vector and bytevector ops to the VM. That
should provide a considerable speedup to programs that use those data
structures.

As far as brainfuck goes:

On Wed 24 Jun 2009 14:03, Andy Wingo <address@hidden> writes:

>     brainfuck@(guile-user)> ,c ++]

    brainfuck@(guile-user)> ,c ++]
    Disassembly of #<objcode b7073dc0>:

       0    (make-int8:0)                   ;; 0
       1    (load-symbol "make-vector")     ;; make-vector
      16    (link-now)                      
      17    (variable-ref)                  
      18    (make-int16 117 48)             ;; 30000
      21    (make-int8:0)                   ;; 0
      22    (call 2)                        
      24    (local-set 1)                   
      26    (local-set 0)                   

The prolog, as before

      28    (local-ref 1)                   
      30    (local-ref 0)                   
      32    (local-ref 1)                   
      34    (local-ref 0)                   
      36    (vector-ref)                    
      37    (make-int8:1)                   ;; 1
      38    (add)                           
      39    (vector-set)                    

One +

      40    (local-ref 1)                   
      42    (local-ref 0)                   
      44    (local-ref 1)                   
      46    (local-ref 0)                   
      48    (vector-ref)                    
      49    (make-int8:1)                   ;; 1
      50    (add)                           
      51    (vector-set)                    

The other +.

      52    (void)                          
      53    (return)   

Here we push "the unspecified value" and return.

As far as performance goes, I took the fibonacci program from
http://www.hevanet.com/cristofd/brainfuck/fib.b:

    >++++++++++>+>+[
        [+++++[>++++++++<-]>.<++++++[>--------<-]+<<<]>.>>[
            [-]<[>+<-]>>[<<+>+>-]<[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-
                [>+<-[>+<-[>+<-[>[-]>+>+<<<-[>+<-]]]]]]]]]]]+>>>
        ]<<<
    ]
    This program doesn't terminate; you will have to kill it.
    Daniel B Cristofani (cristofdathevanetdotcom)
    http://www.hevanet.com/cristofd/brainfuck/

and let it run for about 3 seconds, wall time. The last number that it
printed was:

   
271651113667355860622427102019076226843364138595316927370091609703323530354645264253440817026771386351610030043817601548972412867287338615983131

I then switched back to Scheme, did a (define x that-number), then:

  (define (find-fibo n a b)
    (let ((c (+ a b)))
      (write c) (newline)
       (if (= c x)
           n
           (find-fibo (1+ n) b c))))
  ,t (find-fibo 3 1 1)
   => 688
  clock utime stime cutime cstime gctime
   0.15  0.01  0.00   0.00   0.00   0.00

That is to say, brainfuck computed and printed the 688 first elements of
the fibonacci sequence in about 3 seconds.

The "write" is find-fibo in there to test output speed. Without it
find-fibo executes in 0.01 s. With it, and my stupid gnome-terminal,
0.15 or 0.20 s.

I think that means the brainfuck implementation is doing pretty well, to
do bignum math at that speed, only having 1+ and 1- as its operators...

Andy
-- 
http://wingolog.org/




reply via email to

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