Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Java
Expertise: Intermediate
Nov 30, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Use System.currentTimeMills(); Instead of new Date();

This tip is for when you want to place an action after a time gap between two occurrences (for example, to invalidate an unused session after some permitted time, or to note the total time use of a resource). Instead of storing the starting time of the first occurrence (event) and the ending time of next occurrence (event) as in block A, follow the procedure shown in block B.
//block A
Date start = new Date();
//after some thing
Date end  = new Date();
//Do some thing with start and end to find the time difference 

//block B
long start = System.currentTimeMills();
//after some thing
long end  = System.currentTimeMills();

long timeUsed = end - start;
//do something with timeUsed

The technique shown in block B avoids the unnecessary creation and garbage collection of two Objects, hence increasing performance.
Raveendra Babu
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date