[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/elisp-benchmarks 8ca8641e1ec 34/54: Add EIEIO benchmark
From: |
Pip Cet |
Subject: |
scratch/elisp-benchmarks 8ca8641e1ec 34/54: Add EIEIO benchmark |
Date: |
Mon, 30 Dec 2024 22:40:43 -0500 (EST) |
branch: scratch/elisp-benchmarks
commit 8ca8641e1ec7e065833b57ceacebf7ff4d046862
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.
---
elisp-benchmarks/benchmarks/elb-eieio.el | 49 ++++++++++++++++++++++
.../benchmarks/{pcase.el => elb-pcase.el} | 30 +++----------
elisp-benchmarks/benchmarks/fibn-rec.el | 33 ---------------
elisp-benchmarks/benchmarks/fibn-tc.el | 35 ----------------
elisp-benchmarks/benchmarks/fibn.el | 46 ++++++++++++++++++--
elisp-benchmarks/elisp-benchmarks.el | 10 ++---
6 files changed, 102 insertions(+), 101 deletions(-)
diff --git a/elisp-benchmarks/benchmarks/elb-eieio.el
b/elisp-benchmarks/benchmarks/elb-eieio.el
new file mode 100644
index 00000000000..f234ac7af71
--- /dev/null
+++ b/elisp-benchmarks/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/elisp-benchmarks/benchmarks/pcase.el
b/elisp-benchmarks/benchmarks/elb-pcase.el
similarity index 52%
rename from elisp-benchmarks/benchmarks/pcase.el
rename to elisp-benchmarks/benchmarks/elb-pcase.el
index bca5de2283e..49de1beb8e8 100644
--- a/elisp-benchmarks/benchmarks/pcase.el
+++ b/elisp-benchmarks/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/elisp-benchmarks/benchmarks/fibn-rec.el
b/elisp-benchmarks/benchmarks/fibn-rec.el
deleted file mode 100644
index a8e4b6c9681..00000000000
--- a/elisp-benchmarks/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/elisp-benchmarks/benchmarks/fibn-tc.el
b/elisp-benchmarks/benchmarks/fibn-tc.el
deleted file mode 100644
index 83d571beee7..00000000000
--- a/elisp-benchmarks/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/elisp-benchmarks/benchmarks/fibn.el
b/elisp-benchmarks/benchmarks/fibn.el
index af53477600b..b410a2151e6 100644
--- a/elisp-benchmarks/benchmarks/fibn.el
+++ b/elisp-benchmarks/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/elisp-benchmarks.el
b/elisp-benchmarks/elisp-benchmarks.el
index 90e064287c4..4c1a20a0f59 100644
--- a/elisp-benchmarks/elisp-benchmarks.el
+++ b/elisp-benchmarks/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)
- scratch/elisp-benchmarks 0b955aeabbc 45/54: ; * elisp-benchmarks.el: Update copyright year, (continued)
- scratch/elisp-benchmarks 0b955aeabbc 45/54: ; * elisp-benchmarks.el: Update copyright year, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 5d3a6564227 53/54: Add "make elisp-benchmarks" target, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks b4b10726cda 54/54: New script to import an elpa module, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 81cd14929b9 12/54: * Use the Emacs native compiler if available, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 6326535d976 22/54: * Fix for new `native-compile' interface and bump new version, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks c171f1b8144 33/54: * elisp-benchmarks.el (elisp-benchmarks-run): Fix for non-native emacs, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 400690828d1 52/54: Add "elisp-benchmarks" package from ELPA, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 17c6be0ee5c 19/54: * benchmarks/pcase.el: Don't hide the real `pcase.el`, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 49619b889c0 28/54: * elisp-benchmarks.el: Bump new version., Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 85f201476ab 36/54: * benchmarks/elb-smie.el: New benchmark, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 8ca8641e1ec 34/54: Add EIEIO benchmark,
Pip Cet <=
- scratch/elisp-benchmarks 49031182944 37/54: * benchmarks/elb-bytecomp.el: New benchmark, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 58be34f645c 43/54: * benchmarks/elb-smie.el (elb-font-lock-entry): New benchmark, Pip Cet, 2024/12/30
- scratch/elisp-benchmarks d75e4e0b7d9 47/54: * elisp-benchmarks.el: Bump new version., Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 5738562f549 48/54: * elisp-benchmarks.el (native-comp-speed, compilation-safety): Fix warning., Pip Cet, 2024/12/30
- scratch/elisp-benchmarks 7159ce37b01 49/54: * elisp-benchmarks.el: Bump new version., Pip Cet, 2024/12/30