Subtraction v Hex2Dec in vbscript

Lets say I had to iterate through a loop of 1000 rows of a text file and at each row I had to take a value and do one of the following:
1) If the value were a decimal value with 6 digits, subtract 100,000 from the value
2) If the value were a hex value, convert it to decimal.

Which would be quicker/use fewer resources?

Thank you!
Bob SchneiderCo-OwnerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
You can use my article on how to time code to test it, but something like this is probably the fastest.

MyLong = CLng("&h" & HexString)
0
Bill PrewCommented:
I don't think there would be a significant different over a 1000 record file, or a reasonably current computer.  That being said, I'd probably need a little more to go on, like what assumptions can be made, and what level of protection is needed.  Meaning, can there be bad data, and how is it to be nadled - like numbers with more or less than 6 digits, text strings that have spaces or characters outside the 0-F range,  etc.  Will the input always be only one of the two types you mentioned, or will the code have to determine the class of the data on each line and then act accordingly?

I guess as always, the more info you can share the better the responses here.

~bp
0
Bill PrewCommented:
Here's a simple test, save as a VBS and run with CSCRIPT.  I had to go a lot higher than 1000 iterations to get any significant time as you can see.  The subtraction seems to take about 60% of the time converting hex to Long does, at least with this crude data.

max = 10000000

t1 = Timer()
For i = 1 to max
    d = 999999 - 100000
Next
t2 = Timer()
Wscript.Echo t2-t1

t1 = Timer()
For i = 1 to max
    h = Clng(&hFFFF)
Next
t2 = Timer()
Wscript.Echo t2-t1

Open in new window

~bp
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Bill PrewCommented:
Making it work a little harder, this statement takes longer, so for me each test takes about 1 second...

d = 100000 - 1

~bp
0
Bob SchneiderCo-OwnerAuthor Commented:
Thanks everyone.  Here is more information:  I time races 5k, marathon, trithlons, etc) and I encode my own RFID tags.  I have to make sure that there is little or no reasonable chance of conflicting with things like rfid tags that are put into shoes, etc.  However, ultimately I have to have decimal numbers to work with.  So the two options I have landed on are these:

1) I could encode the tags using 6 decimal digits (I have never seen a six-digit decimal rfid value come through my system).  For instance, rfid tag 100001 would be used for bib #1, rfid tag 100002 would go on bib #2, etc.  Then I just loop through and subtract 100000 from each tag before processing the results.

2) I could encode the tags using hex numbers and just convert to decimal prior to processing the results.

I prefer the first method because it is human-readable but it is even more important to process quickly.

Thanks for any additional clarity you can provide.  I will look at the above links, code, suggestions, ...
0
Bill PrewCommented:
I agree the first method you mention seems like the most friendly and clearer.  I think performance shouldn't be your concern, it won't take any meaningful time in either case.  Go with what makes sense logically and is the best solution from a design and usability perspective, and the tiny amount of extra processing time doesn't even come into play.

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.