Effacer les filtres
Effacer les filtres

why regexprep much slower than strrep

4 vues (au cours des 30 derniers jours)
Oleg Komarov
Oleg Komarov le 16 Nov 2014
Consider the following simplified example:
str = cellstr(repmat('987_890',1e5,1));
timeit(@()strrep(str,'_',''))
timeit(@()regexprep(str,'_',''))
strrep is ~3x faster than regexprep() on R014b - Win7 - cpu i5 3rd gen.
I reckon regexprep carries some overhead for being more flexible but I would expect it to be slightly slower than strrep unless it does the replacement on the go (to allow backtracking). However, in this simple substitution I hoped the engine was smart enough to recognize it does not need to backtrack.
Any thoughts?

Réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by