
{filelink=6315}
public class Chronométrage
{
/** Chronométrer une opération **/
public static void main(String[] args) throws Exception
{
long tempsDebut = System.currentTimeMillis();
for (int i = 0; i < 30; i++)
{
System.out.println(i);
Thread.sleep(100);
}
long tempsFin = System.currentTimeMillis();
float seconds = (tempsFin - tempsDebut) / 1000F;
System.out.println("Opération effectuée en: "+ Float.toString(seconds) + " secondes.");
}
}
//0.625 secondes.
/*
Affichage:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Opération effectuée en: 3.063 secondes.
*/