;; Test speeds of different project detect machanisms. (require 'ede) (defun find-ede-proj-with-ldf-predicate (ldf-file) "Predicate for finding EDE projects with `locate-dominating-file'. Argument LDF-FILE is the current directory file from LDF." (let ((types ede-project-class-files) (ret nil)) ;; Loop over all types, loading in the first type that we find. (while (and types (not ret)) (if (ede-dir-to-projectfile-simple (car types) ldf-file) (progn ;; We found one! Require it now since we will need it. ;;(require (oref (car types) file)) (setq ret (car types))) (setq types (cdr types)))) ret)) (defmethod ede-dir-to-projectfile-simple ((this ede-project-autoload) dir) "Simplified version of `ede-dir-to-projectfile'." (let* ((d (file-name-as-directory dir)) (pf (oref this proj-file)) (f (when (stringp pf) (expand-file-name pf (or root d)))) ) (when (and f (file-exists-p f)) f))) (defun find-ede-proj-with-ldf-predicate-full (ldf-file) "Predicate for finding EDE projects with `locate-dominating-file'. Argument LDF-FILE is the current directory file from LDF." (let ((types ede-project-class-files) (ret nil)) ;; Loop over all types, loading in the first type that we find. (while (and types (not ret)) (if (ede-dir-to-projectfile (car types) ldf-file) (progn ;; We found one! Require it now since we will need it. ;;(require (oref (car types) file)) (setq ret (car types))) (setq types (cdr types)))) ret)) (defun detect-with-ldf () "Detect using `locate-dominating-file'." (locate-dominating-file (buffer-file-name) "INSTALL")) (defun detect-with-ldf-ede-simple () "Detect using `locate-dominating-file' using a simplifed EDE predicate." (locate-dominating-file (buffer-file-name) 'find-ede-proj-with-ldf-predicate)) (defun detect-with-ldf-ede-full () "Detect using `locate-dominating-file' using an EDE predicate." (locate-dominating-file (buffer-file-name) 'find-ede-proj-with-ldf-predicate-full)) (defun detect-with-ede () "Detect using EDE's project detector." (ede-current-project)) (defun detect-with-ede-file-detect () "Detect using EDE's file based project detector." (ede-directory-project-p default-directory)) (defun detect-with-ede-no-buffer-cache () "Detect using EDE's file detect that uses no buffer cache info." (ede-directory-get-open-project default-directory 'ROOT)) (defun detect-with-ede-buffer-init-hook () "Detect using EDE's buffer initialization hook." (ede-initialize-state-current-buffer)) ;(ede-toplevel-project default-directory)) (defun detection-speed () "Try out different detection schemes." (interactive) (dolist (DM '(detect-with-ldf detect-with-ldf-ede-simple detect-with-ldf-ede-full detect-with-ede detect-with-ede-file-detect detect-with-ede-no-buffer-cache detect-with-ede-buffer-init-hook )) (let* ((start (current-time)) (index 100) (out (while (> index 0) (funcall DM) (setq index (1- index)))) (end (current-time))) (message "Detect %S took %.4f seconds" DM (float-time (time-subtract end start))))))