mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-18 20:10:47 +00:00
Move back to using average speed when measuring and tuning. Be more
precise when choosing index for measurement.
This commit is contained in:
parent
70a81077ab
commit
d67825c4cd
59
vlf-tune.el
59
vlf-tune.el
@ -95,21 +95,19 @@ but don't change batch size. If t, measure and change."
|
|||||||
|
|
||||||
(defun vlf-tune-closest-index (size)
|
(defun vlf-tune-closest-index (size)
|
||||||
"Get closest measurement index corresponding to SIZE."
|
"Get closest measurement index corresponding to SIZE."
|
||||||
(max 0 (1- (min (round size vlf-tune-step)
|
(let ((step (float vlf-tune-step)))
|
||||||
(/ vlf-tune-max vlf-tune-step)))))
|
(max 0 (1- (min (round size step) (round vlf-tune-max step))))))
|
||||||
|
|
||||||
(defmacro vlf-tune-add-measurement (vec size time)
|
(defmacro vlf-tune-add-measurement (vec size time)
|
||||||
"Add at an appropriate position in VEC new SIZE TIME measurement.
|
"Add at an appropriate position in VEC new SIZE TIME measurement.
|
||||||
VEC is a vector of (mean time . count) elements ordered by size."
|
VEC is a vector of (mean time . count) elements ordered by size."
|
||||||
`(when vlf-tune-enabled
|
`(when (and vlf-tune-enabled (not (zerop ,size)))
|
||||||
(or ,vec (setq ,vec (vlf-tune-initialize-measurement)))
|
(or ,vec (setq ,vec (vlf-tune-initialize-measurement)))
|
||||||
(let* ((idx (vlf-tune-closest-index ,size))
|
(let* ((idx (vlf-tune-closest-index ,size))
|
||||||
(existing (aref ,vec idx)))
|
(existing (aref ,vec idx)))
|
||||||
(aset ,vec idx (let ((count (1+ (cdr existing)))) ;recalculate mean
|
(aset ,vec idx (let ((count (1+ (cdr existing)))) ;recalculate mean
|
||||||
(cons (/ (+ (* (1- count) (car existing))
|
(cons (/ (+ (* (1- count) (car existing))
|
||||||
(/ (* ,time (1+ idx) ;aproximate time
|
(/ ,size ,time))
|
||||||
vlf-tune-step) ;for this size
|
|
||||||
,size))
|
|
||||||
count)
|
count)
|
||||||
count))))))
|
count))))))
|
||||||
|
|
||||||
@ -188,14 +186,15 @@ SIZE is number of bytes that are saved."
|
|||||||
(defun vlf-tune-score (types index)
|
(defun vlf-tune-score (types index)
|
||||||
"Cumulative speed over TYPES which is alist of (type coef) for INDEX."
|
"Cumulative speed over TYPES which is alist of (type coef) for INDEX."
|
||||||
(catch 'result
|
(catch 'result
|
||||||
(let ((score 0))
|
(let ((score 0)
|
||||||
(dolist (el types (/ (* (1+ index) vlf-tune-step) score))
|
(size (* (1+ index) vlf-tune-step)))
|
||||||
(let ((sc (if (consp el)
|
(dolist (el types (/ size score))
|
||||||
(vlf-tune-assess (car el) (cadr el) index)
|
(let ((bps (if (consp el)
|
||||||
(vlf-tune-assess el 1 index))))
|
(vlf-tune-assess (car el) (cadr el) index)
|
||||||
(if (zerop sc)
|
(vlf-tune-assess el 1 index))))
|
||||||
|
(if (zerop bps)
|
||||||
(throw 'result nil)
|
(throw 'result nil)
|
||||||
(setq score (+ score sc))))))))
|
(setq score (+ score (/ size bps)))))))))
|
||||||
|
|
||||||
(defun vlf-tune-conservative (types &optional index)
|
(defun vlf-tune-conservative (types &optional index)
|
||||||
"Adjust `vlf-batch-size' with `vlf-tune-step' in case of better score.
|
"Adjust `vlf-batch-size' with `vlf-tune-step' in case of better score.
|
||||||
@ -245,22 +244,24 @@ MIN and MAX may specify interval of indexes to search."
|
|||||||
max (or max (1- (/ (min vlf-tune-max
|
max (or max (1- (/ (min vlf-tune-max
|
||||||
(/ vlf-file-size 2))
|
(/ vlf-file-size 2))
|
||||||
vlf-tune-step))))
|
vlf-tune-step))))
|
||||||
(if (< (- max min) 3)
|
(or (< max 1)
|
||||||
(vlf-tune-conservative types (round (+ min max) 2))
|
(if (< (- max min) 3)
|
||||||
(let* ((right-idx (round (+ min (* 3 max)) 4))
|
(vlf-tune-conservative types (round (+ min max) 2))
|
||||||
(right (vlf-tune-score types right-idx)))
|
(let* ((right-idx (round (+ min (* 3 max)) 4))
|
||||||
(if (null right)
|
(right (vlf-tune-score types right-idx)))
|
||||||
(setq vlf-batch-size (* (1+ right-idx) vlf-tune-step))
|
(if (null right)
|
||||||
(let* ((left-idx (round (+ (* 3 min) max) 4))
|
(setq vlf-batch-size (* (1+ right-idx)
|
||||||
(left (vlf-tune-score types left-idx)))
|
vlf-tune-step))
|
||||||
(cond ((null left)
|
(let* ((left-idx (round (+ (* 3 min) max) 4))
|
||||||
(setq vlf-batch-size (* (1+ left-idx)
|
(left (vlf-tune-score types left-idx)))
|
||||||
vlf-tune-step)))
|
(cond ((null left)
|
||||||
((< right left)
|
(setq vlf-batch-size (* (1+ left-idx)
|
||||||
(vlf-tune-best types min
|
vlf-tune-step)))
|
||||||
(round (+ max min) 2)))
|
((< right left)
|
||||||
(t (vlf-tune-best types (round (+ max min) 2)
|
(vlf-tune-best types min
|
||||||
max))))))))))
|
(round (+ max min) 2)))
|
||||||
|
(t (vlf-tune-best types (round (+ max min) 2)
|
||||||
|
max)))))))))))
|
||||||
|
|
||||||
(provide 'vlf-tune)
|
(provide 'vlf-tune)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user