1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-01-31 02:00:47 +00:00

Change vlf-tune-get-optimal to optimize on total time of primitive

operations, also fix hexl timing functions not to book in cases where
hexl is already (not) active.
This commit is contained in:
Andrey Kotlarski 2014-09-07 18:05:13 +03:00
parent 0d2c096ed6
commit ca564988e0
2 changed files with 37 additions and 19 deletions

View File

@ -158,6 +158,10 @@ Return nil if nothing found."
(if success (if success
(vlf-update-buffer-name) (vlf-update-buffer-name)
(vlf-move-to-chunk match-chunk-start match-chunk-end)) (vlf-move-to-chunk match-chunk-start match-chunk-end))
(setq vlf-batch-size (vlf-tune-get-optimal
(if (derived-mode-p 'hexl-mode)
'(:hexl :dehexlify :insert :encode)
'(:insert :encode))))
(let* ((match-end (or (byte-to-position (- match-pos-end (let* ((match-end (or (byte-to-position (- match-pos-end
vlf-start-pos)) vlf-start-pos))
(point-max))) (point-max)))

View File

@ -160,15 +160,17 @@ SIZE is number of bytes that are saved."
(defun vlf-tune-hexlify () (defun vlf-tune-hexlify ()
"Activate `hexl-mode' and save time it takes." "Activate `hexl-mode' and save time it takes."
(let ((time (car (vlf-time (hexl-mode))))) (or (derived-mode-p 'hexl-mode)
(vlf-tune-add-measurement vlf-tune-hexl-bps (let ((time (car (vlf-time (hexl-mode)))))
hexl-max-address time))) (vlf-tune-add-measurement vlf-tune-hexl-bps
hexl-max-address time))))
(defun vlf-tune-dehexlify () (defun vlf-tune-dehexlify ()
"Exit `hexl-mode' and save time it takes." "Exit `hexl-mode' and save time it takes."
(let ((time (car (vlf-time (hexl-mode-exit))))) (if (derived-mode-p 'hexl-mode)
(vlf-tune-add-measurement vlf-tune-dehexlify-bps (let ((time (car (vlf-time (hexl-mode-exit)))))
hexl-max-address time))) (vlf-tune-add-measurement vlf-tune-dehexlify-bps
hexl-max-address time))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; tuning ;;; tuning
@ -238,20 +240,26 @@ If APPROXIMATE is t, do approximation for missing values."
index t)) index t))
0))) 0)))
(defun vlf-tune-score (types index &optional approximate) (defun vlf-tune-score (types index &optional approximate time-max)
"Calculate cumulative speed over TYPES for INDEX. "Calculate cumulative speed over TYPES for INDEX.
If APPROXIMATE is t, do approximation for missing values." If APPROXIMATE is t, do approximation for missing values.
If TIME-MAX is non nil, return cumulative time instead of speed.
If it is number, stop as soon as cumulative time gets equal or above."
(catch 'result (catch 'result
(let ((time 0) (let ((time 0)
(size (* (1+ index) vlf-tune-step))) (size (* (1+ index) vlf-tune-step))
(dolist (el types (/ size time)) (cut-time (numberp time-max)))
(dolist (el types (if time-max time
(/ size time)))
(let ((bps (if (consp el) (let ((bps (if (consp el)
(vlf-tune-assess (car el) (cadr el) index (vlf-tune-assess (car el) (cadr el) index
approximate) approximate)
(vlf-tune-assess el 1 index approximate)))) (vlf-tune-assess el 1 index approximate))))
(if (zerop bps) (if (zerop bps)
(throw 'result nil) (throw 'result nil)
(setq time (+ time (/ size bps))))))))) (setq time (+ time (/ size bps)))
(and cut-time (<= time-max time)
(throw 'result nil))))))))
(defun vlf-tune-conservative (types &optional index) (defun vlf-tune-conservative (types &optional index)
"Adjust `vlf-batch-size' to best nearby value over TYPES. "Adjust `vlf-batch-size' to best nearby value over TYPES.
@ -348,17 +356,23 @@ Suitable for multiple batch operations."
(vlf-tune-binary types 0 max-idx))))))) (vlf-tune-binary types 0 max-idx)))))))
(defun vlf-tune-get-optimal (types) (defun vlf-tune-get-optimal (types)
"Get best batch size according to existing measurements over TYPES." "Get best batch size according to existing measurements over TYPES.
Best is considered where primitive operations total closest to second."
(let ((max-idx (1- (/ (min vlf-tune-max (/ (1+ vlf-file-size) 2)) (let ((max-idx (1- (/ (min vlf-tune-max (/ (1+ vlf-file-size) 2))
vlf-tune-step))) vlf-tune-step)))
(idx 0)
(best-idx 0) (best-idx 0)
(best-bps 0) (best-time-diff 1))
(idx 0)) (while (and (not (zerop best-time-diff)) (< idx max-idx))
(while (< idx max-idx) (let ((time-diff (vlf-tune-score types idx t
(let ((bps (vlf-tune-score types idx t))) (1+ best-time-diff))))
(and bps (< best-bps bps) (when time-diff
(setq best-idx idx (setq time-diff (if (< 1 time-diff)
best-bps bps))) (- time-diff 1)
(- 1 time-diff)))
(if (< time-diff best-time-diff)
(setq best-idx idx
best-time-diff time-diff))))
(setq idx (1+ idx))) (setq idx (1+ idx)))
(* (1+ best-idx) vlf-tune-step))) (* (1+ best-idx) vlf-tune-step)))