unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: guile-devel <guile-devel@gnu.org>
Subject: Re: data-crunching in guile
Date: Fri, 26 Jun 2009 14:09:16 +0200	[thread overview]
Message-ID: <m31vp7mc2b.fsf@pobox.com> (raw)
In-Reply-To: <m3ljnhon41.fsf@pobox.com> (Andy Wingo's message of "Wed, 24 Jun 2009 14:03:10 +0200")

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 <wingo@pobox.com> 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/




      parent reply	other threads:[~2009-06-26 12:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-24 12:03 data-crunching in guile Andy Wingo
2009-06-25  7:26 ` Neil Jerram
2009-06-25  8:04 ` Ludovic Courtès
2009-06-25 21:08   ` Andy Wingo
2009-06-25 22:47     ` Neil Jerram
2009-06-26 14:37       ` Andy Wingo
2009-06-26 21:25         ` Neil Jerram
2009-06-26 12:09 ` Andy Wingo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m31vp7mc2b.fsf@pobox.com \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).