Sunday, 15 July 2012

datetime - Get system clock/time in C# without using any objects? -



datetime - Get system clock/time in C# without using any objects? -

i'm developing application in c# requires many function calls (100-1000 per second) happen @ specific times. however, there extremely tight specs on latency of application, , due latency increment associated garbage collection, it's not feasible me utilize datetime or timer objects. there way can access scheme time primitive type, without having create datetime objects?

tl;dr: there analogue java's system.currenttimemillis() c#?

what makes think datetime allocates objects? it's value type. no need heap allocation, , no need garbage collection. (as tomtom says, if have hard latency requirements, you'll need real-time operating scheme etc. if have "low" latency requirements, that's different matter.)

you should able utilize datetime.now or datetime.utcnow without issues - utcnow faster, doesn't perform time zone conversions.

as example, time 100 1000000 calls datetime.utcnow , using hour property, , on laptop takes 3.5 seconds. using ticks property (which doesn't involve much computation) takes 1.2 seconds. without using property, takes 1 second.

so if you're performing 1000 calls per second, it's going irrelevant.

c# datetime time

No comments:

Post a Comment