;;; func-freq.el --- -*- lexical-binding: t; -*- ;; Copyright (C) 2021 Arthur Miller ;; Author: Arthur Miller ;; Keywords: ;; 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 . ;;; Commentary: ;; ;;; Code: (defun ff-print (map) (maphash (lambda (k v) (print (format "%s: %s" k v))) map)) (defun ff-collect-funcs-and-macros (src &optional keyword) (with-temp-buffer (insert-file-contents-literally src) (goto-char (point-min)) (let (sxp features) (while (setq sxp (ignore-errors (read (current-buffer)))) (when (and (listp sxp) (equal (car sxp) keyword)) (push (cadr sxp) features))) features))) (defun ff-freq-seq (dir-tree) (let ((fmap (make-hash-table :test 'equal)) (mmap (make-hash-table :test 'equal)) (srcs (directory-files-recursively dir-tree "\\.el$"))) (dolist (src srcs) (dolist (f (ff-collect-funcs-and-macros src 'defun)) (puthash f 0 fmap)) (dolist (f (ff-collect-funcs-and-macros src 'defmacro)) (puthash f 0 mmap))))) (defun ff-freq-thr (dir-tree) (let (threads (fmap (make-hash-table :test 'equal)) (mmap (make-hash-table :test 'equal)) (srcs (directory-files-recursively dir-tree "\\.el$"))) (dolist (src srcs) (push (make-thread #'(lambda () (dolist (f (ff-collect-funcs-and-macros src 'defun)) (puthash f 0 fmap) ;;(thread-yield) ) (dolist (f (ff-collect-funcs-and-macros src 'defmacro)) (puthash f 0 mmap) ;;(thread-yield) ))) threads)) (dolist (thread threads) (thread-join thread)))) (defun ff-collect-macros (dir-tree map) (let ((srcs (directory-files-recursively dir-tree "\\.el$"))) (dolist (src srcs) (dolist (f (ff-collect-funcs-and-macros src 'defmacro)) (puthash f 0 map) ;;(thread-yield) )))) (defun ff-collect-functions (dir-tree map) (let ((srcs (directory-files-recursively dir-tree "\\.el$"))) (dolist (src srcs) (dolist (f (ff-collect-funcs-and-macros src 'defun)) (puthash f 0 map) ;;(thread-yield) )))) (defun ff-freq-thr2 (dir-tree) (let (fthr mthr (fmap (make-hash-table :test 'equal)) (mmap (make-hash-table :test 'equal))) (setq mthr (make-thread #'(lambda () (ff-collect-macros dir-tree fmap)))) (setq fthr (make-thread #'(lambda () (ff-collect-functions dir-tree mmap)))) (thread-join mthr) (thread-join fthr))) (benchmark-run 3 (ff-freq-seq (expand-file-name "~/repos/emacs/lisp"))) (benchmark-run 3 (ff-freq-thr (expand-file-name "~/repos/emacs/lisp"))) (benchmark-run 3 (ff-freq-thr2 (expand-file-name "~/repos/emacs/lisp"))) (provide 'func-freq) ;;; func-freq.el ends here