1 ;;; tramp-time.el --- Performance tests for Tramp
3 ;; Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, processes
8 ;; This file is free software: you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;; This package runs performance tests on Tramp. It expects that the
24 ;; Tramp lisp directory is included in the load path. Preferably,
25 ;; Tramp's Lisp files should be compiled.
27 ;; The test can be adapted by changing `tramp-verbose', or the test
28 ;; file name, in the `let' clause. It is expected that the test file
29 ;; should be accessible without password prompting.
31 ;; Three tests are run. The first one is just performing
32 ;; (file-exists-p test-file) and (file-attributes test-file). With
33 ;; this test, Tramp's initialization time shall be checked. Caching
34 ;; file properties should not influence the result.
36 ;; The second and third tests are executing 1000 times (file-exists-p
37 ;; test-file) and (file-attributes test-file), respectively. This
38 ;; will be heavily influenced by caching the results.
40 ;; The test can be run with "emacs -l tramp-time.el"
42 ;; Initially, I've got the following results on my Pentium III 700MHz,
43 ;; 256MB RAM, GNU/Debian Linux 2.6.11, Tramp compiled with the
44 ;; respective (X)Emacs version:
46 ;; Tramp Emacs 20.7 Emacs 21.4 Emacs 22.0 XEmacs 21.4 XEmacs 21.5
48 ;; 2.0.51 14.0 sec 14.0 sec 3.2 sec 3.0 sec (crash)
49 ;; 3.0 sec 4.0 sec 10.0 sec 5.0 sec (crash)
50 ;; 19.0 sec 19.0 sec 36.8 sec 25.0 sec (crash)
52 ;; 2.1.4 - 1.0 sec 0.8 sec 1.0 sec (crash)
53 ;; - 2.0 sec 1.7 sec 2.0 sec (crash)
54 ;; - 2.0 sec 1.7 sec 2.0 sec (crash)
56 ;; Note that Tramp 2.1.4 is applicable for (X)Emacs 21 upwards.
57 ;; Milliseconds are provided by Emacs 22 only. XEmacs 21.5 (from CVS)
58 ;; crashes with both Tramp 2.0.51 and 2.1.4 - no idea why.
65 ;; Initialise profiling
68 (elp-instrument-package "tramp"))
70 ;; Initialise debugging
72 ;(find-file "~/src/tramp/lisp/tramp.el")
73 ;(let ((edebug-all-defs t)) (eval-current-buffer))
74 ;(goto-char (point-min))
75 ;(re-search-forward "defun tramp-send-command-and-check")
77 ;(edebug-set-global-break-condition
78 ; (and (bufferp (get-buffer "*result*"))
79 ; (with-current-buffer (get-buffer "*result*") (= (point-min) (point)))))
81 (defun run-test (operation)
82 (insert (format "Start 1000x (%s \"%s\")\n" operation test-file))
83 ;; We call it once in order to receive complete caching times.
84 (funcall operation test-file)
85 (setq start-time (current-time))
87 (funcall operation test-file))
88 (setq stop-time (current-time))
89 (insert (format "Stop 1000x (%s \"%s\") %s sec\n"
90 operation test-file (tramp-time-diff stop-time start-time)))
93 (switch-to-buffer "*result*")
94 (delete-other-windows)
95 (insert (with-current-buffer elp-results-buffer (buffer-string)))))
97 (let ((tramp-default-proxies-alist nil) (tramp-default-host nil)
98 (tramp-default-method-alist nil) (tramp-default-method nil)
99 (tramp-default-user-alist nil) (tramp-default-user nil)
100 (tramp-verbose 0) (vc-handled-backends nil)
102 (if (string-match "2\.0" tramp-version)
103 (tramp-make-tramp-file-name nil "ssh" nil "localhost" "/")
104 (tramp-make-tramp-file-name "ssh" nil "localhost" "/")))
105 start-time stop-time)
107 ;; Cleanup Tramp buffers.
109 (when (string-match "\\*\\(debug \\)?tramp/" (buffer-name b))
113 ;; Initialise Result buffer.
114 (switch-to-buffer "*result*")
118 "Test accessing \"%s\", emacs-version %s, tramp-version %s, debug level %d, %s compiled version, %s persistent data\n"
123 (if (byte-code-function-p (symbol-function 'tramp-message)) "" " not")
124 (if (and (fboundp 'tramp-get-connection-property)
125 (with-parsed-tramp-file-name test-file nil
126 (tramp-get-connection-property v "uname" nil)))
130 ;; First test. This includes setting up the connection.
131 (insert "Start initial connection\n")
132 (setq start-time (current-time))
133 (file-exists-p test-file)
134 (file-attributes test-file)
135 (setq stop-time (current-time))
136 (insert (format "Stop initial connection %s sec\n"
137 (tramp-time-diff stop-time start-time)))
138 (when (featurep 'elp)
140 (switch-to-buffer "*result*")
141 (delete-other-windows)
142 (insert (with-current-buffer elp-results-buffer (buffer-string))))
145 ;; Second test. `file-exists-p' just runs "-e test-file" if not cached.
146 (run-test 'file-exists-p)
149 ;; Third test. `file-attributes' might run a perl script if not cached.
150 (run-test 'file-attributes)
153 ; (run-test 'directory-files)
156 ; (run-test 'directory-files-and-attributes)
159 (when (featurep 'elp)
160 (kill-buffer elp-results-buffer)))
164 ;; * Make it running under test-harness.el.