fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Foreach vs. ForNext

Foreach vs. ForNext 10 months 1 week ago #5800

  Karl-Heinz's Avatar Topic Author Karl-Heinz Offline Posts: 264
i made a test to see how fast "foreach" works compared to "For...next" in conjunction with strings. The attached app removes char by char all leading zeros from a string.

the initial string is:

c1:= replicate ( "0" , 4500000 ) + "500205"

ok, not a real world string size ;-), but it´s almost impossible to detect the elapsed time without using such a big number. Overall the performance of the good old "for...next" isn´t that bad - if Substr2()/Substr3() is used instead of Substr().


The results on my win8.1 64Bit laptop are:

size of string: 4500006

*500205* 0,0299999999988358 secs FOREACH loop
*500205* 0,0400000000081491 secs STRING loop
*500205* 0,119999999995343 secs FORNEXT loop Substr2() and Substr3()
*500205* 0,970000000001164 secs FORNEXT loop Substr()

Note: To be able to compile the code in <vo> and <core>, i´m using as a workaround c'0' instead of '0' to compare a char.

regards
Karl-Heinz
Attachments:

Please Log in or Create an account to join the conversation.

Foreach vs. ForNext 10 months 1 week ago #5802

  PaulB's Avatar PaulB Offline Posts: 15
Karl-Heinz

Interesting, thanks for the intel!! Can you show loop code?


Cheers,

Paul Bartlett

Please Log in or Create an account to join the conversation.

Foreach vs. ForNext 10 months 1 week ago #5804

  FFF's Avatar FFF Offline Posts: 574
Attached viaf? That little dash below the posting

Please Log in or Create an account to join the conversation.

Foreach vs. ForNext 10 months 1 week ago #5805

  Chris's Avatar Chris Offline Posts: 1163
Btw, the .viaef file is a simple text file, no need to necessarily use XIDE to get the code. It's very easy to open it in notepad and copy/paste the code from it.

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

  • Page:
  • 1