Your code doesn't compile with OPTION STRICT ON.
Code:
For Counter2 = CounterMin To CounterMax
ObjectOut = CType(Counter, Integer)
Next
Counter2 is never declared.
And it's not surprising that this loop is a lot faster. Because COUNTER is unchanged inside the loop, the compiler is able to HOIST that conversion *OUT* of the loop. I had already noted that in my own goof in that regard in a prior attempt.
If you make them BOTH use COUNTER for the loop as well as for the value conversion, you indeed get the same kinds of times I reported:
Code:
CINT: 3.0744208
CTYPE: 3.1044640
CINT: 3.0644064
CTYPE: 3.2246368
CINT: 3.1445216
CTYPE: 3.1144784
CINT: 3.0243488
CTYPE: 3.0243488 [I swear! exactly identical times on 4th run!]
etc. (I bumped your loop count up to 10,000,000 so I could get reasonably lengthy times. If times are too short, interruptions by the OS--such as screen refresh and task monitor events--can distort times dramatically. You're going to get some variations no matter what, but the longer the loop time the more likely that such interruptions will be spread equally across the two tests. Yes, I know that's more important on my single processor machine than on a dual processor, but don't discount the possible effects even on a dual processor.)
Anyway, try your code again, but change BOTH loops to just use Counter (get rid of Counter2) and see essentially identical results. No fair comparing apples to oranges.