;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/fib.el ;; ;; original Elisp from: ;; elisp-benchmarks ;; ;; Common Lisp version: ;; https://dataswamp.org/~incal/cl/bench/fib.cl ;; ;; commands: [results] ;; $ emacs -Q -batch -l fib.el [8.660 s] ;; $ emacs -Q -batch -l fib.elc [3.386 s] ;; $ emacs -Q -batch -l fib-54a44480-bad305eb.eln [3.159 s] ;; $ sbcl -l fib.cl [0.004 s] ;; ;; (stats) ;; plain -> byte: +156% ;; plain -> native: +174% ;; plain -> sbcl: +216400% ;; ;; byte -> native: +7% ;; byte -> sbcl: +84550% ;; ;; native -> sbcl: +78875% (require 'cl-lib) (defun compare-table (l) (cl-loop for (ni ti) in l with first = t do (setq first t) (cl-loop for (nj tj) in l do (when first (insert "\n") (setq first nil)) (unless (string= ni nj) (let ((imp (* (- (/ ti tj) 1.0) 100))) (when (< 0 imp) (insert (format ";; %s -> %s: %+.0f%%\n" ni nj imp) ))))))) (defun stats () (let ((p '("plain" 8.660)) (b '("byte" 3.386)) (n '("native" 3.159)) (s '("sbcl" 0.004)) ) (compare-table (list p b n s)) )) (defun fib (reps num) (let ((z 0)) (dotimes (_ reps) (let ((p1 1) (p2 1)) (dotimes (_ (- num 2)) (setf z (+ p1 p2) p2 p1 p1 z)))) z)) (let ((beg (float-time))) (fib 100000 10000) (message "%.3f s" (- (float-time) beg)) ) ;; (shell-command "emacs -Q -batch -l \"~/.emacs.d/emacs-init/fib.el\"") ;; (shell-command "emacs -Q -batch -l \"~/.emacs.d/emacs-init/fib.elc\"") ;; (shell-command "emacs -Q -batch -l \"~/.emacs.d/eln-cache/30.0.50-3b889b4a/fib-54a44480-8bbda87b.eln\"") (provide 'fib)