[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#43598: replace-in-string: finishing touches
From: |
Lars Ingebrigtsen |
Subject: |
bug#43598: replace-in-string: finishing touches |
Date: |
Sun, 27 Sep 2020 18:41:39 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Eli Zaretskii <eliz@gnu.org> writes:
> Thanks. Is it possible to have some speed comparison for these two?
This is what I used:
(let ((elems (mapcar (lambda (s)
(let ((start (random 80)))
(cons (substring s start (+ start (random 20)))
s)))
(cl-loop repeat 1000
collect (cl-coerce
(cl-loop repeat 100
collect (+ (random 26) ?a))
'string)))))
(list
(benchmark-run 10000 (dolist (elem elems)
(string-search (car elem) (cdr elem))))
(benchmark-run 10000 (dolist (elem elems)
(string-match (car elem) (cdr elem))))))
=>
((7.47099299 29 3.773541741999992)
(19.673036086 74 9.616665831000006))
This is rather geared towards the weaknesses of string-match, though --
we're blowing through the regexp cache.
If you decrease the number of regexps to 10 and the run to 1000000, we get:
((7.818917279000001 37 4.791844609999998)
(11.049133279 37 4.713127558000011))
And to compare with a "do-nothing" version:
(benchmark-run 10000 (dolist (elem elems)
elem))))
=>
((5.74714395 28 3.722243896000009))
Using that as a baseline, the difference is 2s vs 5.2s.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
- bug#43598: replace-in-string: finishing touches, (continued)
- bug#43598: replace-in-string: finishing touches, Mattias Engdegård, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Lars Ingebrigtsen, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Mattias Engdegård, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Lars Ingebrigtsen, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Mattias Engdegård, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Eli Zaretskii, 2020/09/27
- bug#43598: replace-in-string: finishing touches,
Lars Ingebrigtsen <=
- bug#43598: replace-in-string: finishing touches, Eli Zaretskii, 2020/09/27
- bug#43598: replace-in-string: finishing touches, Lars Ingebrigtsen, 2020/09/26
bug#43598: replace-in-string: finishing touches, Lars Ingebrigtsen, 2020/09/26