News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Instr() timings

Started by jj2007, September 22, 2015, 10:42:12 AM

Previous topic - Next topic

zedd151


33979 lines found
Genuine Intel(R) CPU           T2060  @ 1.60GHz
351 ms  for finding 1465185 lines containing [the] using CRT strstr()
529 ms  for finding 1465185 lines containing [the] using Masm32 find$()
437 ms  for finding 1465185 lines containing [the] using PellesC strstr
324 ms  for finding 1489830 lines containing [the] using MB Instr_()
226 ms  for finding 1489830 lines containing [the] using faster Instr_()

757 ms  for finding 418276 lines containing [ther] using CRT strstr()
829 ms  for finding 418276 lines containing [ther] using Masm32 find$()
1104 ms for finding 418276 lines containing [ther] using PellesC strstr
796 ms  for finding 442232 lines containing [ther] using MB Instr_()
373 ms  for finding 442232 lines containing [ther] using faster Instr_()

813 ms  for finding 205004 lines containing [there] using CRT strstr()
888 ms  for finding 205004 lines containing [there] using Masm32 find$()
1197 ms for finding 205004 lines containing [there] using PellesC strstr
866 ms  for finding 233995 lines containing [there] using MB Instr_()
393 ms  for finding 233995 lines containing [there] using faster Instr_()

868 ms  for finding 42771 lines containing [theref] using CRT strstr()
894 ms  for finding 42771 lines containing [theref] using Masm32 find$()
1283 ms for finding 42771 lines containing [theref] using PellesC strstr
925 ms  for finding 65402 lines containing [theref] using MB Instr_()
407 ms  for finding 65402 lines containing [theref] using faster Instr_()

859 ms  for finding 42665 lines containing [therefo] using CRT strstr()
899 ms  for finding 42665 lines containing [therefo] using Masm32 find$()
1280 ms for finding 42665 lines containing [therefo] using PellesC strstr
916 ms  for finding 65296 lines containing [therefo] using MB Instr_()
407 ms  for finding 65296 lines containing [therefo] using faster Instr_()

867 ms  for finding 42665 lines containing [therefor] using CRT strstr()
901 ms  for finding 42665 lines containing [therefor] using Masm32 find$()
1285 ms for finding 42665 lines containing [therefor] using PellesC strstr
921 ms  for finding 65296 lines containing [therefor] using MB Instr_()
411 ms  for finding 65296 lines containing [therefor] using faster Instr_()

872 ms  for finding 42665 lines containing [therefore] using CRT strstr()
917 ms  for finding 42665 lines containing [therefore] using Masm32 find$()
1289 ms for finding 42665 lines containing [therefore] using PellesC strstr
930 ms  for finding 65296 lines containing [therefore] using MB Instr_()
407 ms  for finding 65296 lines containing [therefore] using faster Instr_()

867 ms  for finding 42665 lines containing [therefore] using CRT strstr()
911 ms  for finding 42665 lines containing [therefore] using Masm32 find$()
1290 ms for finding 42665 lines containing [therefore] using PellesC strstr
930 ms  for finding 65296 lines containing [therefore] using MB Instr_()
407 ms  for finding 65296 lines containing [therefore] using faster Instr_()

3031 ms total for faster Instr_(), 6254 ms for CRT, crt:mb=2.06
364     bytes for InstrJJw

dedndave

prescott w/htt
Intel(R) Pentium(R) 4 CPU 3.00GHz
303 ms  for finding 1465185 lines containing [the] using CRT strstr()
469 ms  for finding 1465185 lines containing [the] using Masm32 find$()
259 ms  for finding 1489830 lines containing [the] using MB Instr_()
232 ms  for finding 1489830 lines containing [the] using faster Instr_()

737 ms  for finding 418276 lines containing [ther] using CRT strstr()
792 ms  for finding 418276 lines containing [ther] using Masm32 find$()
617 ms  for finding 442232 lines containing [ther] using MB Instr_()
451 ms  for finding 442232 lines containing [ther] using faster Instr_()

810 ms  for finding 205004 lines containing [there] using CRT strstr()
862 ms  for finding 205004 lines containing [there] using Masm32 find$()
669 ms  for finding 233995 lines containing [there] using MB Instr_()
471 ms  for finding 233995 lines containing [there] using faster Instr_()

857 ms  for finding 42771 lines containing [theref] using CRT strstr()
856 ms  for finding 42771 lines containing [theref] using Masm32 find$()
715 ms  for finding 65402 lines containing [theref] using MB Instr_()
490 ms  for finding 65402 lines containing [theref] using faster Instr_()

859 ms  for finding 42665 lines containing [therefo] using CRT strstr()
869 ms  for finding 42665 lines containing [therefo] using Masm32 find$()
717 ms  for finding 65296 lines containing [therefo] using MB Instr_()
513 ms  for finding 65296 lines containing [therefo] using faster Instr_()

858 ms  for finding 42665 lines containing [therefor] using CRT strstr()
863 ms  for finding 42665 lines containing [therefor] using Masm32 find$()
717 ms  for finding 65296 lines containing [therefor] using MB Instr_()
491 ms  for finding 65296 lines containing [therefor] using faster Instr_()

860 ms  for finding 42665 lines containing [therefore] using CRT strstr()
877 ms  for finding 42665 lines containing [therefore] using Masm32 find$()
716 ms  for finding 65296 lines containing [therefore] using MB Instr_()
492 ms  for finding 65296 lines containing [therefore] using faster Instr_()

855 ms  for finding 42665 lines containing [therefore] using CRT strstr()
880 ms  for finding 42665 lines containing [therefore] using Masm32 find$()
715 ms  for finding 65296 lines containing [therefore] using MB Instr_()
494 ms  for finding 65296 lines containing [therefore] using faster Instr_()

3634 ms total for faster Instr_(), 6139 ms for CRT, crt:mb=1.69

Siekmanski


Intel(R) Core(TM) i7-4930K CPU @ 3.40GHz
123 ms  for finding 1465185 lines containing [the] using CRT strstr()
196 ms  for finding 1465185 lines containing [the] using Masm32 find$()
105 ms  for finding 1489830 lines containing [the] using MB Instr_()
78 ms   for finding 1489830 lines containing [the] using faster Instr_()

306 ms  for finding 418276 lines containing [ther] using CRT strstr()
329 ms  for finding 418276 lines containing [ther] using Masm32 find$()
282 ms  for finding 442232 lines containing [ther] using MB Instr_()
135 ms  for finding 442232 lines containing [ther] using faster Instr_()

333 ms  for finding 205004 lines containing [there] using CRT strstr()
352 ms  for finding 205004 lines containing [there] using Masm32 find$()
309 ms  for finding 233995 lines containing [there] using MB Instr_()
140 ms  for finding 233995 lines containing [there] using faster Instr_()

356 ms  for finding 42771 lines containing [theref] using CRT strstr()
360 ms  for finding 42771 lines containing [theref] using Masm32 find$()
330 ms  for finding 65402 lines containing [theref] using MB Instr_()
149 ms  for finding 65402 lines containing [theref] using faster Instr_()

355 ms  for finding 42665 lines containing [therefo] using CRT strstr()
362 ms  for finding 42665 lines containing [therefo] using Masm32 find$()
302 ms  for finding 65296 lines containing [therefo] using MB Instr_()
145 ms  for finding 65296 lines containing [therefo] using faster Instr_()

367 ms  for finding 42665 lines containing [therefor] using CRT strstr()
357 ms  for finding 42665 lines containing [therefor] using Masm32 find$()
306 ms  for finding 65296 lines containing [therefor] using MB Instr_()
133 ms  for finding 65296 lines containing [therefor] using faster Instr_()

358 ms  for finding 42665 lines containing [therefore] using CRT strstr()
382 ms  for finding 42665 lines containing [therefore] using Masm32 find$()
325 ms  for finding 65296 lines containing [therefore] using MB Instr_()
131 ms  for finding 65296 lines containing [therefore] using faster Instr_()

356 ms  for finding 42665 lines containing [therefore] using CRT strstr()
362 ms  for finding 42665 lines containing [therefore] using Masm32 find$()
302 ms  for finding 65296 lines containing [therefore] using MB Instr_()
132 ms  for finding 65296 lines containing [therefore] using faster Instr_()

1043 ms total for faster Instr_(), 2554 ms for CRT, crt:mb=2.45
364     bytes for InstrJJw
Creative coders use backward thinking techniques as a strategy.

TWell

Test program with PellesC that use Bible.txt.
200 times 'Jesus Christ'
Result:load time: 11 ms
pocrt strstr
1284 ms 40200
msvcrt strstr
2003 ms 40200
MbInstr
2581 ms 40200
Press ENTER
What goes wrong?

jj2007

Quote from: TWell on September 24, 2015, 07:24:03 PMWhat goes wrong?

The timings look OK, but I'm surprised that you get 40200 lines where I get 49820 ::)
What is the size (in bytes) of your bible.txt?

The current MasmBasic Instr() is not particularly fast, roughly on par with CRT and Masm32 InString. Its strengths are the case-insensitive and full word options. The new one I am testing now will be about twice as fast but the two options will not be available.

331 ms  for finding 49820 lines containing [Jesus] using CRT strstr()
93 ms   for finding 49820 lines containing [Jesus] using InstrB
207 ms  for finding 49820 lines containing [Jesus] using PellesC strstr
274 ms  for finding 49820 lines containing [Jesus] using MB Instr_()
106 ms  for finding 49820 lines containing [Jesus] using faster Instr_()

331 ms  for finding 49820 lines containing [Jesus] using CRT strstr()
94 ms   for finding 49820 lines containing [Jesus] using InstrB
205 ms  for finding 49820 lines containing [Jesus] using PellesC strstr
271 ms  for finding 49820 lines containing [Jesus] using MB Instr_()
100 ms  for finding 49820 lines containing [Jesus] using faster Instr_()

332 ms  for finding 49820 lines containing [Jesus] using CRT strstr()
96 ms   for finding 49820 lines containing [Jesus] using InstrB
210 ms  for finding 49820 lines containing [Jesus] using PellesC strstr
272 ms  for finding 49820 lines containing [Jesus] using MB Instr_()
103 ms  for finding 49820 lines containing [Jesus] using faster Instr_()

TWell

Bible.txt 4 397 206 bytes.
There is 201 'Jesus Christ'  and 2 'JESUS CHRIST'
I use
WindowsGrep 2.3
grepwin
too.
Bible.txt load time: 10 ms
counter: 200, search string: 'Jesus'
pocrt strstr    1389 ms 196200
msvcrt strstr   1846 ms 196200
MB MbInstr      2027 ms 196200

Bible.txt load time: 10 ms
counter: 200, search string: 'therefore'
pocrt strstr    5576 ms 163800
msvcrt strstr   3715 ms 163800
MB MbInstr      3196 ms 163800

jj2007

Quote from: TWell on September 24, 2015, 11:40:33 PM
Bible.txt 4 397 206 bytes.
There is 201 'Jesus Christ'  and 2 'JESUS CHRIST'

grepWin finds indeed 981 * Jesus. The MasmBasic equivalent is...
Print Str$("Jesus found %i times", Count(Cat$(FileRead$("Bible.txt")), "Jesus", 1))
... and it finds 981 matches, or 990 with option 1, i.e. case-insensitive.
Option 0 takes 8 ms, the case-insensitive search takes 11 ms, of which most is FileRead$().

jj2007

So now Instr_(Fast, main$, sub$, mode) has become part of the new MasmBasic version. Timings are competitive with the CRT:

Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
326 ms  for finding 49820 lines containing [Jesus] using CRT strstr()
95 ms   for finding 49820 lines containing [Jesus] using Instr_(fast, ...)
290 ms  for finding 49820 lines containing [Jesus] using MB Instr_()
101 ms  for finding 49820 lines containing [Jesus] using InstrW()

556     ms for Instr_(Fast, pHaystack, pNeedle, mode), fast : normal=0.705
1804    ms for CRT strstr, crt : fast=3.24


In the end, I had to decide between a byte scanner (using pcmpeqb) and a word scanner (using pcmpeqw). The byte scanner won, although it is marginally slower, for the simple reason that it can handle single byte "needles". In case-sensitive mode, the new algo is 2...3 times faster than CRT strstr, depending mainly on the first byte of the substring.

Thanks for all the testing :icon14:

TWell

load time: 8 ms
pocrt strstr    1117 ms 40200
msvcrt strstr   1833 ms 40200
MB InsJB         380 ms 40200

jj2007

Once more - a new version with slightly improved performance:
33979 lines found
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
24 ms   for finding 1834866 lines containing [] using CRT strstr()
27 ms   for finding 1834866 lines containing [] using Instr_(fast, ...)
23 ms   for finding 1834866 lines containing [] using PellesC strstr
0 ms    for finding 0 lines containing [] using Masm32 InString
266 ms  for finding 1834866 lines containing [] using MB Instr_()
30 ms   for finding 1834866 lines containing [] using InstrW()

149 ms  for finding 267624 lines containing [J] using CRT strstr()
60 ms   for finding 267624 lines containing [J] using Instr_(fast, ...)
150 ms  for finding 267624 lines containing [J] using PellesC strstr
276 ms  for finding 267624 lines containing [J] using Masm32 InString
245 ms  for finding 267624 lines containing [J] using MB Instr_()
241 ms  for finding 267624 lines containing [J] using InstrW()

258 ms  for finding 151848 lines containing [Je] using CRT strstr()
64 ms   for finding 151848 lines containing [Je] using Instr_(fast, ...)
159 ms  for finding 151848 lines containing [Je] using PellesC strstr
285 ms  for finding 151848 lines containing [Je] using Masm32 InString
218 ms  for finding 151848 lines containing [Je] using MB Instr_()
82 ms   for finding 151848 lines containing [Je] using InstrW()

267 ms  for finding 59886 lines containing [Jer] using CRT strstr()
66 ms   for finding 59886 lines containing [Jer] using Instr_(fast, ...)
164 ms  for finding 59886 lines containing [Jer] using PellesC strstr
289 ms  for finding 59886 lines containing [Jer] using Masm32 InString
221 ms  for finding 59886 lines containing [Jer] using MB Instr_()
84 ms   for finding 59886 lines containing [Jer] using InstrW()

274 ms  for finding 3942 lines containing [Jeri] using CRT strstr()
67 ms   for finding 3942 lines containing [Jeri] using Instr_(fast, ...)
170 ms  for finding 3942 lines containing [Jeri] using PellesC strstr
295 ms  for finding 3942 lines containing [Jeri] using Masm32 InString
229 ms  for finding 3942 lines containing [Jeri] using MB Instr_()
84 ms   for finding 3942 lines containing [Jeri] using InstrW()

272 ms  for finding 3186 lines containing [Jeric] using CRT strstr()
72 ms   for finding 3186 lines containing [Jeric] using Instr_(fast, ...)
172 ms  for finding 3186 lines containing [Jeric] using PellesC strstr
292 ms  for finding 3186 lines containing [Jeric] using Masm32 InString
227 ms  for finding 3186 lines containing [Jeric] using MB Instr_()
85 ms   for finding 3186 lines containing [Jeric] using InstrW()

356     ms for Instr_(Fast, ...), fast : normal=0.587
606     ms total for InsW
1244    ms for CRT strstr, crt : fast=3.49


IMHO it can't get much faster, but of course, the Boyer-Moore brigade has not yet shown up ;)

P.S.: If you extract it to the folder where the bible.txt sits, it won't download it again.

dedndave

prescott w/htt
33979 lines found
Intel(R) Pentium(R) 4 CPU 3.00GHz
58 ms   for finding 1834866 lines containing [] using CRT strstr()
60 ms   for finding 1834866 lines containing [] using Instr_(fast, ...)
0 ms    for finding 0 lines containing [] using Masm32 InString
583 ms  for finding 1834866 lines containing [] using MB Instr_()
92 ms   for finding 1834866 lines containing [] using InstrW()

282 ms  for finding 267624 lines containing [J] using CRT strstr()
170 ms  for finding 267624 lines containing [J] using Instr_(fast, ...)
503 ms  for finding 267624 lines containing [J] using Masm32 InString
549 ms  for finding 267624 lines containing [J] using MB Instr_()
519 ms  for finding 267624 lines containing [J] using InstrW()

426 ms  for finding 151848 lines containing [Je] using CRT strstr()
175 ms  for finding 151848 lines containing [Je] using Instr_(fast, ...)
516 ms  for finding 151848 lines containing [Je] using Masm32 InString
477 ms  for finding 151848 lines containing [Je] using MB Instr_()
246 ms  for finding 151848 lines containing [Je] using InstrW()

436 ms  for finding 59886 lines containing [Jer] using CRT strstr()
182 ms  for finding 59886 lines containing [Jer] using Instr_(fast, ...)
524 ms  for finding 59886 lines containing [Jer] using Masm32 InString
497 ms  for finding 59886 lines containing [Jer] using MB Instr_()
259 ms  for finding 59886 lines containing [Jer] using InstrW()

443 ms  for finding 3942 lines containing [Jeri] using CRT strstr()
184 ms  for finding 3942 lines containing [Jeri] using Instr_(fast, ...)
552 ms  for finding 3942 lines containing [Jeri] using Masm32 InString
507 ms  for finding 3942 lines containing [Jeri] using MB Instr_()
258 ms  for finding 3942 lines containing [Jeri] using InstrW()

444 ms  for finding 3186 lines containing [Jeric] using CRT strstr()
184 ms  for finding 3186 lines containing [Jeric] using Instr_(fast, ...)
528 ms  for finding 3186 lines containing [Jeric] using Masm32 InString
512 ms  for finding 3186 lines containing [Jeric] using MB Instr_()
262 ms  for finding 3186 lines containing [Jeric] using InstrW()

955     ms for Instr_(Fast, ...), fast : normal=0.584
1636    ms total for InsW
2089    ms for CRT strstr, crt : fast=2.19

Siekmanski


33979 lines found
Intel(R) Core(TM) i7-4930K CPU @ 3.40GHz
37 ms   for finding 1834866 lines containing [] using CRT strstr()
25 ms   for finding 1834866 lines containing [] using Instr_(fast, ...)
0 ms    for finding 0 lines containing [] using Masm32 InString
228 ms  for finding 1834866 lines containing [] using MB Instr_()
26 ms   for finding 1834866 lines containing [] using InstrW()

128 ms  for finding 267624 lines containing [J] using CRT strstr()
56 ms   for finding 267624 lines containing [J] using Instr_(fast, ...)
241 ms  for finding 267624 lines containing [J] using Masm32 InString
214 ms  for finding 267624 lines containing [J] using MB Instr_()
211 ms  for finding 267624 lines containing [J] using InstrW()

173 ms  for finding 151848 lines containing [Je] using CRT strstr()
60 ms   for finding 151848 lines containing [Je] using Instr_(fast, ...)
249 ms  for finding 151848 lines containing [Je] using Masm32 InString
188 ms  for finding 151848 lines containing [Je] using MB Instr_()
70 ms   for finding 151848 lines containing [Je] using InstrW()

178 ms  for finding 59886 lines containing [Jer] using CRT strstr()
62 ms   for finding 59886 lines containing [Jer] using Instr_(fast, ...)
254 ms  for finding 59886 lines containing [Jer] using Masm32 InString
195 ms  for finding 59886 lines containing [Jer] using MB Instr_()
73 ms   for finding 59886 lines containing [Jer] using InstrW()

183 ms  for finding 3942 lines containing [Jeri] using CRT strstr()
62 ms   for finding 3942 lines containing [Jeri] using Instr_(fast, ...)
257 ms  for finding 3942 lines containing [Jeri] using Masm32 InString
200 ms  for finding 3942 lines containing [Jeri] using MB Instr_()
74 ms   for finding 3942 lines containing [Jeri] using InstrW()

183 ms  for finding 3186 lines containing [Jeric] using CRT strstr()
62 ms   for finding 3186 lines containing [Jeric] using Instr_(fast, ...)
257 ms  for finding 3186 lines containing [Jeric] using Masm32 InString
201 ms  for finding 3186 lines containing [Jeric] using MB Instr_()
74 ms   for finding 3186 lines containing [Jeric] using InstrW()

327     ms for Instr_(Fast, ...), fast : normal=0.619
528     ms total for InsW
882     ms for CRT strstr, crt : fast=2.70

391     bytes for InstrJJb
384     bytes for InsJb16
Creative coders use backward thinking techniques as a strategy.

TWell

pocrt.dll version 8 for testing and reference for system msvcrt.dll.
How msvcrt.dll differs between OS versions?

dedndave

recent OS versions have added a lot of extra code, trying to overcome security issues (buffer overflow)
from what i understand, they are much slower, too

TWell

Can you run jj2007 test with pocrt.dll too?