vb.net - Conversion of Date into hour/minute/second incredibly slow -


i need date cyclically convert components (hour, minute, second). following code quite well.

dim time_hour integer dim time_minute integer dim time_second integer dim time_ms integer dim storednow date  storednow = time_hour = storednow.hour time_minute = storednow.minute time_second = storednow.second time_ms = storednow.millisecond 

however, have found performance problem. have examined source code profiler, , conversion of components seems incredibly slow. there quick way current time disassemble component parts?

take @ extremoptimization.com. there few interesting mathematic thoughts this. here's possible sketch of solution:

dim ticks long dim time_hour integer dim time_minute integer dim time_second integer dim time_ms integer dim storednow date  storednow = ticks = storednow.ticks time_ms = cint((ticks \ 10000) mod 86400000) time_hour = cint(math.bigmul(time_ms >> 7, 9773437) >> 38) time_ms -= 3600000 * time_hour time_minute = cint(((math.bigmul(time_ms >> 5, 2290650)) >> 32)) time_ms -= 60000 * time_minute time_second = ((time_ms >> 3) * 67109) >> 23 time_ms -= 1000 * time_second 

but careful. source code not maintainable. conversion reliable, i'm not sure if else understand doing on first view. reward conversion, 25 times faster classic approach. however, still should think approach , if not possible avoid this.


Comments