04-24-2012 05:15 PM - edited 04-24-2012 05:15 PM
I found a faster code.
(with assembler and a call dll library)
Search one character or a substring in a string
Methods : SpreadSheet, Replace, Count .... and ASM_DLL
(Count method works only to search one character)
"ASM_DLL method" works for both cases, one character or a substring
attached file : Benchmark
string 50e6 characters
substring : "abc"
SpreadSheat - 504ms
Replace - 428ms
Count - doesn't work if more than one character
ASM_DLL - 71ms
only one character : "a"
04-24-2012 05:25 PM
Well, in all LabVIEW coding challenges so far, external code, such as DLLs are not allowed.
I would never doubt that a hand-coded dll will be faster and I am happy that LabVIEW is within 25% of its speed. That should tell you something.
Don't forget that most computers have multiple cores and LabVIEW would easily allow this problem to be split onto multiple parallel cores. We should be able to get 4x faster on a quad core CPU, easily beating your dll (which of course could also be adapted for multiple cores). 😄
04-24-2012 06:05 PM - edited 04-24-2012 06:05 PM
OK, here's a quick "pure LabVIEW" draft that easily beats your dll.
The first four versions use about 12% CPU (I7-2600K) while the parallel version uses 30% CPU. There might still be room for improvement. This is just a 2minute modification of the existing code, I am sure it could be tuned more. 😉

04-24-2012 06:43 PM
Q6600 core2 quad
ASM_DLL - 78ms
Parallel count - 73ms (congratulation altenbach)
8 instances ... woaw !
i see a "P" in your For Loop ... i don"t know this "P" (??) ...
how do that ? From where comes this "P"
![]()
04-24-2012 06:47 PM - edited 04-24-2012 06:53 PM
right-click the FOR loop...configure iteration parallelism.
See also this page, for example.
Of course nothing prevents you from placing your dll in a parallel FOR loop, now you are done in 25ms on my computer. 😄

04-24-2012 06:54 PM
ok, thank you altenback
... hummmm ... I don't admit defeat!
i will be back.... ![]()
04-24-2012 06:54 PM
04-24-2012 07:00 PM
woaww ... beautiful !!!
you go too fast
... altenback, the knight of LV ... yes, i agree, really.
04-24-2012 07:44 PM - edited 04-24-2012 07:48 PM
on my computer (Q6600 4 core - 2,4Ghz)
before 78 ms (26% cpu) ==> after 62 ms (69% cpu)
again, thank you ... Altenbach
a good day today, I learned something new! ("P") ![]()
04-24-2012 08:09 PM - edited 04-24-2012 08:14 PM
multiple instances will not work with a substring (not only one character)
impossible to cut the string without risking a split in a substring
and in this case ... my dll will give the best result ![]()