Initial Commit
[packages] / xemacs-packages / tramp / test / tramp-time.el
1 ;;; tramp-time.el --- Performance tests for Tramp
2
3 ;; Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4
5 ;; Author: Michael Albinus <michael.albinus@gmx.de>
6 ;; Keywords: comm, processes
7
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.
12
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.
17
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/>.
20
21 ;;; Commentary:
22
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.
26
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.
30
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.
35
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.
39
40 ;; The test can be run with "emacs -l tramp-time.el"
41
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:
45
46 ;; Tramp       Emacs 20.7  Emacs 21.4  Emacs 22.0  XEmacs 21.4  XEmacs 21.5
47 ;;
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)
51 ;;
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)
55
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.
59
60 ;;; Code:
61
62 (require 'time-stamp)
63 (require 'tramp)
64
65 ;; Initialise profiling
66 ;(require 'elp)
67 (when (featurep 'elp)
68   (elp-instrument-package "tramp"))
69
70 ;; Initialise debugging
71 ;(require 'edebug)
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")
76 ;(edebug-defun)
77 ;(edebug-set-global-break-condition
78 ; (and (bufferp (get-buffer "*result*"))
79 ;      (with-current-buffer (get-buffer "*result*") (= (point-min) (point)))))
80
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))
86   (dotimes (i 1000)
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)))
91   (when (featurep 'elp)
92     (elp-results)
93     (switch-to-buffer "*result*")
94     (delete-other-windows)
95     (insert (with-current-buffer elp-results-buffer (buffer-string)))))
96
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)
101       (test-file
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)
106
107   ;; Cleanup Tramp buffers.
108   (mapcar '(lambda (b)
109              (when (string-match "\\*\\(debug \\)?tramp/" (buffer-name b))
110                (kill-buffer b)))
111           (buffer-list))
112
113   ;; Initialise Result buffer.
114   (switch-to-buffer "*result*")
115   (erase-buffer)
116   (insert
117    (format
118     "Test accessing \"%s\", emacs-version %s, tramp-version %s, debug level %d, %s compiled version, %s persistent data\n"
119     test-file
120     emacs-version
121     tramp-version
122     tramp-verbose
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)))
127         "with" "without")))
128   (sit-for 1)
129
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)
139     (elp-results)
140     (switch-to-buffer "*result*")
141     (delete-other-windows)
142     (insert (with-current-buffer elp-results-buffer (buffer-string))))
143   (sit-for 1)
144
145   ;; Second test.  `file-exists-p' just runs "-e test-file" if not cached.
146   (run-test 'file-exists-p)
147   (sit-for 1)
148
149   ;; Third test.  `file-attributes' might run a perl script if not cached.
150   (run-test 'file-attributes)
151   (sit-for 1)
152
153 ;  (run-test 'directory-files)
154 ;  (sit-for 1)
155
156 ;  (run-test 'directory-files-and-attributes)
157 ;  (sit-for 1)
158
159   (when (featurep 'elp)
160     (kill-buffer elp-results-buffer)))
161
162 ;;; TODO:
163
164 ;; * Make it running under test-harness.el.