[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
scratch/elisp-benchmarks 0dc090098dd 34/54: Add EIEIO benchmark
From: |
Pip Cet |
Subject: |
scratch/elisp-benchmarks 0dc090098dd 34/54: Add EIEIO benchmark |
Date: |
Sat, 4 Jan 2025 12:26:35 -0500 (EST) |
branch: scratch/elisp-benchmarks
commit 0dc090098dd7b25675a43b59110dea5f0b3c9912
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/benchmarks/elb-eieio.el | 49 ++++++++++++++++++++++++
benchmarks/benchmarks/{pcase.el => elb-pcase.el} | 30 +++------------
benchmarks/benchmarks/fibn-rec.el | 33 ----------------
benchmarks/benchmarks/fibn-tc.el | 35 -----------------
benchmarks/benchmarks/fibn.el | 46 ++++++++++++++++++++--
benchmarks/elisp-benchmarks.el | 10 ++---
6 files changed, 102 insertions(+), 101 deletions(-)
diff --git a/benchmarks/benchmarks/elb-eieio.el
b/benchmarks/benchmarks/elb-eieio.el
new file mode 100644
index 00000000000..f234ac7af71
--- /dev/null
+++ b/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/benchmarks/benchmarks/pcase.el b/benchmarks/benchmarks/elb-pcase.el
similarity index 52%
rename from benchmarks/benchmarks/pcase.el
rename to benchmarks/benchmarks/elb-pcase.el
index bca5de2283e..49de1beb8e8 100644
--- a/benchmarks/benchmarks/pcase.el
+++ b/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/benchmarks/benchmarks/fibn-rec.el
b/benchmarks/benchmarks/fibn-rec.el
deleted file mode 100644
index a8e4b6c9681..00000000000
--- a/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/benchmarks/benchmarks/fibn-tc.el b/benchmarks/benchmarks/fibn-tc.el
deleted file mode 100644
index 83d571beee7..00000000000
--- a/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/benchmarks/benchmarks/fibn.el b/benchmarks/benchmarks/fibn.el
index af53477600b..b410a2151e6 100644
--- a/benchmarks/benchmarks/fibn.el
+++ b/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/benchmarks/elisp-benchmarks.el b/benchmarks/elisp-benchmarks.el
index 90e064287c4..4c1a20a0f59 100644
--- a/benchmarks/elisp-benchmarks.el
+++ b/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 e6717e1de7f 19/54: * benchmarks/pcase.el: Don't hide the real `pcase.el`, (continued)
- scratch/elisp-benchmarks e6717e1de7f 19/54: * benchmarks/pcase.el: Don't hide the real `pcase.el`, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks f5834702781 23/54: Make `comp-speed' explicit in each benchmark, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 00afe629432 20/54: Add new 'inclist-type-hints' benchmark + tag new version, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 8d15a1e6601 26/54: Make `comp-speed' controllable through a customize, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks a0d6af36237 28/54: * elisp-benchmarks.el: Bump new version., Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 0458ad6d03d 30/54: * elisp-benchmarks.el : Rename feature nativecomp -> feature-nativecompile, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks ba18acd0c17 32/54: ; * benchmarks/pack-unpack.el: Remove unnecessary newlines., Pip Cet, 2025/01/04
- scratch/elisp-benchmarks f43385543fc 46/54: * Handle 'compilation-safety', Pip Cet, 2025/01/04
- scratch/elisp-benchmarks f0132de78c1 47/54: * elisp-benchmarks.el: Bump new version., Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 3dba0bfbf4d 37/54: * benchmarks/elb-bytecomp.el: New benchmark, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 0dc090098dd 34/54: Add EIEIO benchmark,
Pip Cet <=
- scratch/elisp-benchmarks 2eb211695bc 43/54: * benchmarks/elb-smie.el (elb-font-lock-entry): New benchmark, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 6965195a757 49/54: * elisp-benchmarks.el: Bump new version., Pip Cet, 2025/01/04
- scratch/elisp-benchmarks d7f3b38a26b 50/54: elisp-benchmarks.el: Compact output and support setup code, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks a32a99ae8af 54/54: New script to import an elpa module, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 59b2387ba71 52/54: Add "elisp-benchmarks" package from ELPA, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 908c78fe2bb 42/54: ; Prefer HTTPS to HTTP in URLs, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 9f4ff70129a 10/54: * elisp-benchmarks.el: Typo fix, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 30ca0c4dd09 21/54: * elisp-benchmarks.el (elisp-benchmarks-run): Use featurep to detect nativecomp, Pip Cet, 2025/01/04
- scratch/elisp-benchmarks 9df4eede3a4 25/54: Revert "Make `comp-speed' explicit in each benchmark", Pip Cet, 2025/01/04
- scratch/elisp-benchmarks d2c1c63f843 22/54: * Fix for new `native-compile' interface and bump new version, Pip Cet, 2025/01/04