Const vs String speed test

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1168
Joined: Sun Feb 14, 2010 7:11 pm

Const vs String speed test

Post by Bugala »

I couldnt find the old topic anymore where I was having more speed tests, so putting this into a new one.

I made a test about using Strings vs using Consts, and to my surprise, I didn't get any noticeable speed difference, I was expecting Const to being much faster actually.

Code: Select all

Const #TEST = 0
Const #NOT = 1

StartTimer(0)
a = #TEST
b = #NOT
c = 0


For n = 1 To 10000000
If a = #TEST Then c = c + 1
If b = #TEST Then c = c + 1
Next

DebugPrint(GetTimer(0))
ResetTimer(0)


a = "test"
b = "not"
c = 0


For n = 1 To 10000000
If a = "test" Then c = c + 1
If b = "test" Then c = c + 1
Next


DebugPrint(GetTimer(0))
This resulted in taking about 5000 of time in both cases. Different runs resulted in between 4 500 - 5 500 on both, and although there was difference between the results of these two in each run, it would keep switching which one was faster. I guess no point in using one or other from speed point of view.
Post Reply