emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/elisp-benchmarks 7467bf994e: Add EIEIO benchmark


From: Stefan Monnier
Subject: [elpa] externals/elisp-benchmarks 7467bf994e: Add EIEIO benchmark
Date: Mon, 7 Feb 2022 16:17:52 -0500 (EST)

branch: externals/elisp-benchmarks
commit 7467bf994ef710f5898e91c629799eb90cc241ea
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    Add EIEIO benchmark
    
    * benchmarks/elb-eieio.el: New file.
    * benchmarks/elb-pcase.el: Rename from pcase.el to avoid naming conflict.
    * benchmarks/fibn-tc.el, benchmarks/fibn-rec.el: Fold into 
benchmarks/fibn.el.
    * benchmarks/fibn.el: Add a `fibn-named-let` entry.  Keep the same
    number of iterations for all the non-naive fibn entries so they can
    be compared more directly.
    
    * elisp-benchmarks.el (elisp-benchmarks-run): Sort entries.
---
 benchmarks/elb-eieio.el               | 49 +++++++++++++++++++++++++++++++++++
 benchmarks/{pcase.el => elb-pcase.el} | 30 +++++----------------
 benchmarks/fibn-rec.el                | 33 -----------------------
 benchmarks/fibn-tc.el                 | 35 -------------------------
 benchmarks/fibn.el                    | 46 +++++++++++++++++++++++++++++---
 elisp-benchmarks.el                   | 10 +++----
 6 files changed, 102 insertions(+), 101 deletions(-)

diff --git a/benchmarks/elb-eieio.el b/benchmarks/elb-eieio.el
new file mode 100644
index 0000000000..f234ac7af7
--- /dev/null
+++ b/benchmarks/elb-eieio.el
@@ -0,0 +1,49 @@
+;;; elb-eieio.el --- Benchmarking EIEIO operations   -*- lexical-binding: t; 
-*-
+
+;; Copyright (C) 2022  Stefan Monnier
+
+;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'eieio)
+
+(defclass elb--eieio-cons () ((car :initarg :car) (cdr :initarg :cdr)))
+
+(cl-defmethod shared-initialize ((_obj elb--eieio-cons) _slots)
+  (cl-call-next-method))
+
+(cl-defgeneric elb--eieio-length (_x) 0)
+(cl-defmethod  elb--eieio-length ((x elb--eieio-cons))
+  (1+ (elb--eieio-length (slot-value x 'cdr))))
+
+(defun elb-eieio-entry ()
+  (let ((total 0))
+    (dotimes (_ 3000)
+      (let ((l nil))
+        ;; The elb--eieio-length recursion can't deal with more than about
+        ;; 150 elements.
+        (dotimes (i 100)
+          (setq l (make-instance 'elb--eieio-cons :car i :cdr l)))
+        (setq total (+ total (elb--eieio-length l)))))
+    total))
+ 
+(provide 'elb-eieio)
+;;; elb-eieio.el ends here
diff --git a/benchmarks/pcase.el b/benchmarks/elb-pcase.el
similarity index 52%
rename from benchmarks/pcase.el
rename to benchmarks/elb-pcase.el
index bca5de2283..49de1beb8e 100644
--- a/benchmarks/pcase.el
+++ b/benchmarks/elb-pcase.el
@@ -1,6 +1,6 @@
-;;; bench/pcase.el --- Exercise code using pcase  -*- lexical-binding: t; -*-
+;;; elb-pcase.el --- Exercise code using pcase  -*- lexical-binding: t; -*-
 
-;; Copyright (C) 2020-2021 Free Software Foundation, Inc.
+;; Copyright (C) 2020-2022 Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
 
@@ -17,25 +17,6 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
-(eval-and-compile
-  ;; ¡FIXME!  The GNUmakefile of elpa.git uses:
-  ;;
-  ;;    ... -L $(dir $@) -f batch-byte-compile $<
-  ;;
-  ;; to compile each file.  This is handy for some cases such as files in
-  ;; `contrib' subdirectories but for this `pcase.el' file it causes this
-  ;; `pcase.el' to hide the *real* `pcase.el'.  So we workaround this problem
-  ;; here by removing the offending element from `load-path'.  Yuck!
-  ;;
-  ;; We should probably change GNUmakefile instead so it doesn't forcefully
-  ;; add the directory to `load-path', e.g. make this dependent on the
-  ;; presence of special file like `.dont-add-to-load-path'. 
-  (let ((file (if (fboundp 'macroexp-file-name) (macroexp-file-name) ;Emacs≥28
-                (or load-file-name
-                    (bound-and-true-p byte-compile-current-file)))))
-    (when file
-      (setq load-path (remove (file-name-directory file) load-path)))))
-
 ;;; Commentary:
 
 ;; Apply a simple pattern match defined with pcase on the element of a list.
@@ -51,10 +32,10 @@
                                          (1 '(a))
                                          (2 (random 10)))))
 
-(defsubst foo (x)
+(defsubst elb-pcase--foo (x)
   (1+ x))
 
-(defsubst bar (x)
+(defsubst elb-pcase--bar (x)
   (* x x))
 
 (defun elb-pcase (l)
@@ -62,10 +43,11 @@
           counting (pcase x
                      (`(a b) 1)
                      (`(a) 2)
-                     (_ (foo (bar x))))))
+                     (_ (elb-pcase--foo (elb-pcase--bar x))))))
 
 (defun elb-pcase-entry ()
   (cl-loop repeat 20000
           do (elb-pcase elb-pcase-list)))
 
 (provide 'elb-pcase)
+;;; elb-pcase ends here.
diff --git a/benchmarks/fibn-rec.el b/benchmarks/fibn-rec.el
deleted file mode 100644
index a8e4b6c968..0000000000
--- a/benchmarks/fibn-rec.el
+++ /dev/null
@@ -1,33 +0,0 @@
-;; -*- lexical-binding: t; -*-
-
-;; Copyright (C) 2019 Free Software Foundation, Inc.
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Fibonacci sequence recursive algo.
-
-(defun elb-fib (n)
-  (cond ((= n 0) 0)
-       ((= n 1) 1)
-       (t (+ (elb-fib (- n 1))
-             (elb-fib (- n 2))))))
-
-(defun elb-fibn-rec-entry ()
-  (elb-fib 37))
-
-(provide 'fibn-rec)
diff --git a/benchmarks/fibn-tc.el b/benchmarks/fibn-tc.el
deleted file mode 100644
index 83d571beee..0000000000
--- a/benchmarks/fibn-tc.el
+++ /dev/null
@@ -1,35 +0,0 @@
-;; -*- lexical-binding: t; -*-
-
-;; Copyright (C) 2019 Free Software Foundation, Inc.
-
-;; This file is part of GNU Emacs.
-
-;; GNU Emacs is free software: you can redistribute it and/or modify
-;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation, either version 3 of the License, or
-;; (at your option) any later version.
-
-;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;; GNU General Public License for more details.
-
-;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
-
-;;; Commentary:
-
-;; Fibonacci sequence tail recursive algo.
-
-(require 'cl-lib)
-
-(defun elb-fibn-tc (a b count)
-  (if (= count 0)
-      b
-    (elb-fibn-tc (+ a b) a (- count 1))))
-
-(defun elb-fibn-tc-entry ()
-  (cl-loop repeat 1000000
-          do (elb-fibn-tc 1 0 80)))
-
-(provide 'fibn-tc)
diff --git a/benchmarks/fibn.el b/benchmarks/fibn.el
index af53477600..b410a2151e 100644
--- a/benchmarks/fibn.el
+++ b/benchmarks/fibn.el
@@ -1,6 +1,6 @@
 ;; -*- lexical-binding: t; -*-
 
-;; Copyright (C) 2019 Free Software Foundation, Inc.
+;; Copyright (C) 2019, 2022 Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
 
@@ -19,6 +19,8 @@
 
 ;;; Commentary:
 
+;;; Code:
+
 ;; Adapted to elisp from CL version from:
 ;; 
https://drmeister.wordpress.com/2015/07/30/timing-data-comparing-cclasp-to-c-sbcl-and-python/
 
@@ -34,7 +36,45 @@
     z))
 
 (defun elb-fibn-entry ()
-  ;; Use 80 to stay in the fixnum range.
-  (elb-fibn 3000000 80))
+  ;; Use 80 to stay in the fixnum range (on 64bit systems).
+  (elb-fibn 1000000 80))
+
+;; Fibonacci sequence tail recursive algo.
+
+(defun elb-fibn-tc (a b count)
+  (if (= count 0)
+      b
+    (elb-fibn-tc (+ a b) a (- count 1))))
+
+(defun elb-fibn-tc-entry ()
+  (dotimes (_ 1000000)
+    (elb-fibn-tc 1 0 80)))
+
+;; Fibonacci sequence with named-let.
+
+(defun elb-fibn-named-let (count)
+  (named-let loop ((a 1)
+                   (b 0)
+                   (count count))
+    (if (= count 0)
+        b
+      (loop (+ a b) a (- count 1)))))
+
+(defun elb-fibn-named-let-entry ()
+  (dotimes (_ 1000000)
+    (elb-fibn-named-let 80)))
+
+;; Fibonacci sequence with the naive recursive algo.
+
+(defun elb-fibn-rec (n)
+  (cond ((= n 0) 0)
+       ((= n 1) 1)
+       (t (+ (elb-fibn-rec (- n 1))
+             (elb-fibn-rec (- n 2))))))
+
+(defun elb-fibn-rec-entry ()
+  (elb-fibn-rec 37))
+
 
 (provide 'elb-fibn)
+;;; elb-fibn ends here.
diff --git a/elisp-benchmarks.el b/elisp-benchmarks.el
index 90e064287c..4c1a20a0f5 100644
--- a/elisp-benchmarks.el
+++ b/elisp-benchmarks.el
@@ -1,6 +1,6 @@
 ;;; elisp-benchmarks.el --- elisp benchmarks collection -*- lexical-binding:t 
-*-
 
-;; Copyright (C) 2019-2021  Free Software Foundation, Inc.
+;; Copyright (C) 2019-2022  Free Software Foundation, Inc.
 
 ;; Author: Andrea Corallo <akrl@sdf.org>
 ;; Maintainer: Andrea Corallo <akrl@sdf.org>
@@ -56,13 +56,11 @@
 
 (defcustom elb-runs 3
   "Total number of benchmark iterations."
-  :type 'number
-  :group 'elb)
+  :type 'number)
 
 (defcustom elb-speed 3
   "Default `native-comp-speed' to be used for native compiling the benchmarks."
-  :type 'number
-  :group 'elb)
+  :type 'number)
 
 (defconst elb-bench-directory
   (concat (file-name-directory (or load-file-name buffer-file-name))
@@ -122,7 +120,7 @@ RECOMPILE all the benchmark folder when non nil."
                                (when (string-match
                                       "\\`elb-\\(.*\\)-entry\\'" name)
                                  (push (match-string 1 name) names)))))
-                  names)))
+                  (sort names #'string-lessp))))
       ;; (cl-loop for test in tests
       ;;          do (puthash test () res))
       (cl-loop with runs = (or runs elb-runs)



reply via email to

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