From xemacs-m  Mon Dec  9 12:56:18 1996
Received: from palrel1.hp.com (palrel1.hp.com [15.253.72.10]) by xemacs.cs.uiuc.edu (8.8.3/8.8.3) with ESMTP id MAA20193 for <xemacs-beta@xemacs.org>; Mon, 9 Dec 1996 12:56:16 -0600 (CST)
Received: from mordor.rsn.hp.com (mordor.rsn.hp.com [15.99.150.126]) by palrel1.hp.com with ESMTP (8.7.5/8.7.3) id KAA04665 for <xemacs-beta@xemacs.org>; Mon, 9 Dec 1996 10:55:58 -0800 (PST)
Received: (from holder@localhost) by mordor.rsn.hp.com (8.7.1/8.7.1) id NAA00818; Mon, 9 Dec 1996 13:01:57 -0600 (CST)
To: xemacs-beta@xemacs.org
Subject: Re: Benchmarking XEmacs versions (was Re: Additions to Shane Holder's bench.el)
References: <199612090006.SAA17017@xemacs.cs.uiuc.edu> <m2d8wkl6mt.fsf@altair.xemacs.org>
From: Shane Holder <holder@mordor.rsn.hp.com>
Date: 09 Dec 1996 13:01:56 -0600
In-Reply-To: Steven L Baur's message of 08 Dec 1996 19:48:58 -0800
Message-ID: <fawengzk0d7.fsf@mordor.rsn.hp.com>
Lines: 233
X-Mailer: Red Gnus v0.66/Emacs 19.34


I've modified sb-bench.el.  I added naming the bench-mark-? in the ELP
buffer, and also added 2 new benchmarks. Bench-mark-5  generates
10000 random words for bench-mark-6, and bench-mark-6 sorts them.
Emacs doesn't define what and cdar so I also had to add (require 'cl).

My results for 19.15 B2 and 19.34 follow, along with the new code.

HP-UX mordor B.10.20 E 9000/712 2005053784 8-user license
96M ram.

19.15
Function Name  Call Count  Elapsed Time  Average Time
=============  ==========  ============  ============
bench-mark-1   1           32.675728999  32.675728999   <= Tower of Hanoi
bench-mark-2   1           18.625868999  18.625868999   <= Font Lock
bench-mark-3   1           352.25929299  352.25929299   <= Large File scrolling
bench-mark-4   1           0.4285790000  0.4285790000   <= Frame Creation
bench-mark-5   1           8.8115340000  8.8115340000   <= Generate Words
bench-mark-6   1           24.083223000  24.083223000   <= Sort Buffer
bench-mark-7   1           169.17476300  169.17476300   <= Large File bytecompilation

19.34
Function Name  Call Count  Elapsed Time  Average Time
=============  ==========  ============  ============
bench-mark-1   1           3.7362570000  3.7362570000   <= Tower of Hanoi
bench-mark-2   1           13.352772999  13.352772999   <= Font Lock
bench-mark-3   1           174.52945600  174.52945600   <= Large File scrolling
bench-mark-4   1           1.1168240000  1.1168240000   <= Frame Creation
bench-mark-5   1           3.3207589999  3.3207589999   <= Generate Words
bench-mark-6   1           12.798964999  12.798964999   <= Sort Buffer
bench-mark-7   1           99.594148000  99.594148000   <= Large File bytecompilation

;;; sb-bench.el --- a crude benchmark for emacsen
;; Copyright (C) 1987,88,89,90,93,94,95,96 Free Software Foundation, Inc.

;; Author: Shane Holder <holder@rsn.hp.com>
;; Adapted-By: Steve Baur <steve@altair.xemacs.org>

;; This file is part of XEmacs.

;; XEmacs 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 2, or (at your option)
;; any later version.

;; XEmacs 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 XEmacs; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.

;;; Commentary:

;; Adapted from Shane Holder's bench.el by steve@altair.xemacs.org.

;; To run
;; At the shell prompt emacs -q  <= don't load users .emacs
;; M-x byte-compile-file "sb-bench.el"
;; M-x load-file "sb-bench.elc"
;; In the scratch buffer (bench 1)

;;; Code:

;; Use elp to profile benchmarks
(require 'elp)
(require 'cl)				;Emacs doesn't have when and cdar

(defvar bench-large-lisp-file "/home/src/xemacs-19.15-b2/lisp/gnus/gnus.el"
  "Large lisp file to use in benchmarks")

(defvar bench-sort-buffer "*Sort*"
  "File to be used in the sort benchmark")

(defvar bench-sort-number-words 10000
  "Number of words to use in sort benchmark")

(defvar bench-pre-bench-hook nil
  "Hook for individual bench mark initialization.")

(defvar bench-post-bench-hook nil
  "Hook for individual bench mark statistic collection.")

(defvar bench-mark-function-alist
  '((bench-mark-1 . "Tower of Hanoi")
    (bench-mark-2 . "Font Lock")
    (bench-mark-3 . "Large File scrolling")
    (bench-mark-4 . "Frame Creation")
    (bench-mark-5 . "Generate Words")
    (bench-mark-6 . "Sort Buffer")
    (bench-mark-7 . "Large File bytecompilation")))

(defvar bench-enabled-profiling nil
  "If non-nil and the underlying emacs supports it, do function profiling.")

(defvar bench-mark-profile-buffer "*Profile*"
  "Buffer used for collection of profiling data.")

;-----------------------------------------------------------------------------
(defun bench-mark-1 ()
  "How long to complete the tower of hanoi."
  (hanoi 4))

;-----------------------------------------------------------------------------
(defun bench-mark-2 ()
  "How long to fonitfy a large file."
  (find-file bench-large-lisp-file)
  (font-lock-fontify-buffer))

;-----------------------------------------------------------------------------
(defun bench-mark-3 ()
  "How long does it take to scroll down through a large file."
  (let ((buffer-read-only t))
    (goto-char (point-min))
    (while (< (point) (point-max))
      (next-line 1)
      (sit-for 0))))

;-----------------------------------------------------------------------------
(defun bench-mark-4 ()
  "How quickly can emacs create a new frame."
  (make-frame))


;-----------------------------------------------------------------------------
(defun bench-mark-5 ()
  (set-buffer (get-buffer-create bench-sort-buffer))
  (let ((tmp-words bench-sort-number-words))
    (while (not (= tmp-words 0))
      (let ((word-len (random 10)))
	(while (not (= word-len 0))
	  (insert (+ ?a (random 25)))
	  (setq word-len (- word-len 1))))
      (insert "\n")
      (setq tmp-words (- tmp-words 1)))))

(defun bench-mark-6 ()
  ; Sort something
  (set-buffer (get-buffer-create bench-sort-buffer))
  (sort-lines nil (point-min) (point-max))
)

;-----------------------------------------------------------------------------
(defun bench-mark-7 ()
  ; Byte compile a file
  (byte-compile-file bench-large-lisp-file)
)

;=============================================================================
(defun bench-init ()
  "Initialize profiling for bench marking package."
  (if (fboundp 'start-profiling)
      (let ((buf (get-buffer-create bench-mark-profile-buffer)))
	(erase-buffer buf)
	(when (profiling-active-p)
	  (stop-profiling)
	  (clear-profiling-info)))
    (message "Profiling not available in this XEmacs.")
    (sit-for 2)))

(defun bench-profile-start (test-name)
  "Turn on profiling for test `test-name'."
  (when (and bench-enabled-profiling
	     (fboundp 'start-profiling))
    (when (profiling-active-p)
      (stop-profiling))
    (let ((buf (get-buffer-create bench-mark-profile-buffer)))
      (save-excursion
	(set-buffer buf)
	(insert "Test `" test-name "'\n")
	(start-profiling)))))

(defun bench-profile-stop (test-name)
  "Turn off profiling for test `test-name'."
  (when (and bench-enabled-profiling
	     (fboundp 'stop-profiling))
    (stop-profiling)
    (let ((buf (get-buffer-create bench-mark-profile-buffer)))
      (save-excursion
	(set-buffer buf)
	(insert (with-output-to-string
		 (pretty-print-profiling-info)) "\n")))
    (clear-profiling-info)))

(add-hook 'bench-pre-bench-hook 'bench-profile-start)
(add-hook 'bench-post-bench-hook 'bench-profile-stop)

(defun bench (arg)
  "Run a series of benchmarks."
  (interactive "p")
  (elp-instrument-package "bench-mark") ;Only instrument functions
                                        ;beginning with bench-mark
  (bench-init)
  (if (fboundp 'byte-optimize)		;Turn off byte-compile optimization in XEmacs
      (setq byte-optimize nil))
  (let ((benches bench-mark-function-alist))
    (while benches
      (let ((test-name (cdar benches)))
	(run-hook-with-args 'bench-pre-bench-hook test-name)
	(let ((count arg))
	  (while (> count 0)
	    (funcall (caar benches))
	    (setq count (1- count))))
	(setq benches (cdr benches))
	(run-hook-with-args 'bench-post-bench-hook test-name))
      ))
  (elp-results)
  (goto-char (point-min))
  (next-line 2)
  (sort-lines nil (point) (point-max))
  (goto-char (point-min))
  (let ((benches bench-mark-function-alist))
    (while benches
      (let ((test-name (cdar benches))
	    (test-func (caar benches)))
	(search-forward (symbol-name test-func))
	(end-of-line)
	(insert "   <= " test-name))
	(setq benches (cdr benches))
      ))
)

;;; sb-bench.el ends here

-- 
Shane Holder                                 e-mail: holder@rsn.hp.com
Hewlett Packard                               phone:     (214)497-4182
3000 Waterview                       Never underestimate the bandwidth
Richardson, TX 75083                 of a truck moving at 70 MPH.

