strchr(H, CharAsNeedle) is useless. It does nothing more than strstr(H, StringAsNeedle) and is ~2x slower
Reported by Samuel GOUGEON (@sgougeon)
BUG DESCRIPTION:
----------------
strchr() is useless, since Scilab is text-oriented, unlike C and may be Otherlab that are character-oriented.
It does nothing more than strstr(), that can get strings as needles, so in particular single chars as needles.
By the way, strchr() is ~twice slower than strstr().
This slow and weak duplicate should be removed, avoiding slowness, useless choice, help pages and code maintaining.
This would also avoid debugging
-->strchr(["abc ABC" "bcd" "déf DEF" "hij"]', ["c" "c" "é" "k"]')
ans =
!c ABC !
! !
!cd !
! !
!éf DEF !
! !
! !
-->strstr(["abc ABC" "bcd" "déf DEF" "hij"]', ["c" "c" "é" "k"]')
ans =
!c ABC !
! !
!cd !
! !
!éf DEF !
! !
! !
-->n = 10000;
-->tic();
-->for i=1:n, strchr(H, N); end
-->toc()
ans =
0.415
-->tic()
-->for i=1:n, strstr(H, N); end
-->toc()
ans =
0.197
HOW TO REPRODUCE THE BUG:
-------------------------
H = ["abc ABC" "bcd" "déf DEF" "hij"]
N = ["c" "c" "é" "k"]
strchr(H', N')
strstr(H', N')
n = 10000;
tic();
for i=1:n, strchr(H, N); end
toc()
tic()
for i=1:n, strstr(H, N); end
toc()