org-element-cache-map: Report pre-process time in statistics

* lisp/org-element.el (org-element-cache-map): Calculate time elapsed
while filling the cache gaps during pre-processing.
This commit is contained in:
Ihor Radchenko 2021-11-25 22:16:37 +08:00
parent 8ddd95e5a3
commit 49df468849
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 10 additions and 4 deletions

View File

@ -7292,6 +7292,7 @@ the cache."
;; Statistics
(time (float-time))
(predicate-time 0)
(pre-process-time 0)
(count-predicate-calls-match 0)
(count-predicate-calls-fail 0))
;; Skip to first element within region.
@ -7308,9 +7309,13 @@ the cache."
(and (eq granularity 'element)
(or next-re fail-re)))
(let ((org-element-cache-map--recurse t))
(org-element-cache-map
#'ignore
:granularity granularity)
(let ((before-time (float-time)))
(org-element-cache-map
#'ignore
:granularity granularity)
(cl-incf pre-process-time
(- (float-time)
before-time)))
;; Re-assign the cache root after filling the cache
;; gaps.
(setq node (cache-root)))
@ -7474,13 +7479,14 @@ the cache."
(when (and org-element--cache-map-statistics
(or (not org-element--cache-map-statistics-threshold)
(> (- (float-time) time) org-element--cache-map-statistics-threshold)))
(message "Mapped over elements in %S. %d/%d predicate matches. Total time: %f sec. Time running predicates: %f sec (%f sec avg)
(message "Mapped over elements in %S. %d/%d predicate matches. Total time: %f sec. Pre-process time: %f sec. Time running predicates: %f sec (%f sec avg)
Calling parameters: :granularity %S :restrict-elements %S :next-re %S :fail-re %S :from-pos %S :to-pos %S :limit-count %S :after-element %S"
(current-buffer)
count-predicate-calls-match
(+ count-predicate-calls-match
count-predicate-calls-fail)
(- (float-time) time)
pre-process-time
predicate-time
(if (zerop (+ count-predicate-calls-match
count-predicate-calls-fail))