GNU bug report logs -
#43598
replace-in-string: finishing touches
Previous Next
Full log
View this message in rfc822 format
Eli Zaretskii <eliz <at> 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
This bug report was last modified 4 years and 296 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.