Main Content:

What is the VBScript Integer Division operator and how can it help my code?











Jobs in Wipro Infotech & Other Top Companies

- Click here to Register in Shine.com Today!

------------------------------------------------------

- FRESHERS -

Receive SMS Alerts on Walkins Held in Your City

SMS "Your City Name" to (0) 98410 80502



FOR MORE & MORE TECHNICAL INTERVIEW QUESTIONS …, Join Our Group now
http://in.groups.yahoo.com/group/knowledge-base/join/

Since VBScript hides the details of data types so well, sometimes it's easy for a VBScript programmer to forget that the actual storage of a number comes in many different flavours 'behind the scenes'. In VBScript you normally use the / (division) operator to divide one number from another. However, there is an alternative to the normal division operator that may be beneficial to your application, depending on your needs.

First, if you are certain at design time that you will always be dividing integers (numbers with no decimal) AND you wish to recieve an integer output (rounded off, if there are decimals) you can speed up the calculation a little bit by using the integer division operator (\). Since division is already an extremely quick feature most languages, the approximate 10% gain (by my calulation) made by using the integer division operator is quite small. I timed 5 million (5000 000) division operations of random integers at between 9 and 10 seconds. Unless you are doing large numbers of division operations, this gain may not be important to you, however the 10% gain increases to about 25% if the quotient (the output of your division) happens to also be an integer (i.e. 12 \ 2 = 6).

Compare:
' regular division
' @ 10 seconds:
For i = 1 to 500000
    intQuotient = 100 / 3 ' intQuotient = 33.333333...
Next

' integer divison operator
' @ about 9 seconds:
For i = 1 to 500000
    intQuotient = 100 \ 3 ' intQuotient = 33
Next

' integer division w/ natural integer output:
' @ about 7.5 seconds
For i = 1 to 500000
    intQuotient = 100 \ 2 ' intQuotient = 20
Next



Second, if you have floating point number which you wish to round before dividing, the integer division operator automatically does this; consider it a 'side-effect' which you may find useful. In other words plugging numbers with decimals into the integer division operator is the equivalent of this:

Round(Round(numerator) / Round(denominator))



Where numerator is the number being divided and denominator is the number you are dividing by. This is a very specific case but if it's appropriate to what you are doing, the integer division operator will be much faster than the normal, floating point operator.




MNC Jobs in Chennai, Bangalore & Hyderabad

- Click here to Register in Shine.com Today!






BE THE FIRST ONE TO APPLY TO FRESH IT JOBS AS SOON AS IT COMES……JOIN OUR GROUP NOW
http://in.groups.yahoo.com/group/knowledge-base/join/


CareerEnclave.Com ~ We Shape Your Career ~
Keywords
Keywords : Job, job, Jobs, jobs, Career, career, Careers, careers, Employ, employ, Employment, employment, Recruit, recruit, Recruitment, recruitment,recruitment solution, Recruitment Solution, jobsassist, jobassist, jobs-assist, http://www.careerenclave.com/, Naukri, naukri, Naukari, naukari, nokri,india, indian, placement, outsource jobs, Resume Writing, Resume Development, Career Services, Resume blaster, resume flash, resume india, resume, bangalore, mumbai, delhi, hyderabad, chennai, computer, software, hardware, fresher, freshers, experienced, IT, project, projects, vyom, vyomworld, opening, test, papers, counsultancy, address, addresses, infosys, tcs, MBT, wipro, satyam, ibm, microsoft, bosch, siemen, reliance



Jump to: