Vb.net + SQL Server : Speed difference using float vs Decimal -
i'm using vb.net 2013 , sql server 2008r2.
i'm writing financial application , , i'm not sure data type use.
i know decimal more precise float , read using decimal can decrease speed of calculations , speed of application. read using decimals can 20 times slower using float. true , , if yes there solution or should continue use float ?
thank !
use decimal financial applications, period. speed not matter in case. when money lost, users won't happy. cannot argue saying "well, on other hand, fast". regarding 20 times difference on float vs decimal, trust me, won't feel @ all, there more major factors in app's performance. trying synchronize transactions between each other, db locks etc.
edit: regarding 20 times performance difference, true, able reproduce below code:
module module1 sub main() dim f single = 123456792.0f dim fsw new stopwatch fsw.start() = 1 100000000 f *= 1.00000012f next fsw.stop() dim dsw new stopwatch dsw.start() dim d decimal = 123456792.0f = 1 100000000 d *= 1.00000012f next dsw.stop() console.writeline(f) console.writeline("float (ms): " & fsw.elapsedmilliseconds) console.writeline(d) console.writeline("decimal (ms): " & dsw.elapsedmilliseconds) console.writeline("float " & dsw.elapsedmilliseconds / fsw.elapsedmilliseconds & " faster") console.readline() end sub end module
output:
while writing code, got anywhere between 10-20 times different numbers. mentioned before, speed not concern, compare accuracy of both approaches, notice how float off several orders of magnitude. is, of course, synthetic example, shows how people may end 1 dollar on payroll instead of 1000 - imagine reaction.
Comments
Post a Comment