Question:
calculate the execution time of a method called in java program which has it's description in another program?
rahul
2012-05-08 05:46:28 UTC
i have doubt in a java program can u please clarify it as soon as possible.
the code below is used to calculate the execution time of method called.
CipherText.append(mm.encryptString(plaintext));

{

startTimeEnc = System.currentTimeMillis();
StepsText.append("keyword : "+keyworD+'\n');
StepsText.append("PlainText : "+plaintext+'\n');
bytesEnc=plaintext.getBytes().length;

StepsText.append("PlainText size : "+bytesEnc+'\n');
mm= new Blowfishst( keyworD);


CipherText.append(mm.encryptString(plaintext));


endTimeEnc = System.currentTimeMillis();
long exeTimeEnc=(endTimeEnc-startTimeEnc);
System.out.println("execution time="+exeTimeEnc+"MilliSec");
trputEnc=(bytesEnc)/exeTimeEnc;
System.out.println("Throughput="+trputEnc+" bit/Sec");
}

this method " CipherText.append(mm.encryptString(plaintext));" is another program and on running the code i am getting execution time of 109 millisec for differnt data sizes .
can u please explain what is going on i cant understand this and i need different execution times to create graph for analysis
Three answers:
brewster429
2012-05-08 05:53:57 UTC
Aw geezus . . . . .



All that is pertinent here:



long startTime = System.currentTimeMilliseconds();



long endTime = System.currentTimeMilliseconds();

long elapsedTime = endTime - startTime;



Capiche?
James Bond
2012-05-08 13:10:39 UTC
That code is meant to measure the time taken by those four or five lines of code. Not that CipherText.append(...) only.



See the details of currentTimeMilllis() which returns the time in miilliseconds from a stadard date

public static long currentTimeMillis()

Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.

See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC).



Returns:

the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.



The group of statements for which you want to observe the time taken can be achived by calling this function before and after the statements. The diffeence will convey the time consumed by the group of statements.



For detailed analysis you can try tools such as gprof
Anonymous Coward
2012-05-08 13:07:32 UTC
Use very large strings.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...