-1

Hello I am doing a project on programming algorithm measurements

how I can know the time of execution from start to finish and RAM consumption of a class made an algorithm in java and file made in c++.

I need to do from the linux shell because the idea is that these results are stored in variables of Ruby on Rails for web viewing. so I can't use any external program unless this gives me the answer in linux terminal

edymerchk
  • 1,203
  • 13
  • 19

1 Answers1

0

Why not try cat /proc/1234/smaps ?

Here: 1234 is the PID of the application. Also JVM comes with access to methods for getting the amount of free-memory available for the JVM and also the amount of memory used. Runtime.getRuntime().totalMemory() and Runtime.getRuntime().freeMemory() To measure the execution time(not high precision) use the "time" functions.

For C++:

 time_t start_time = time(NULL); 
/*your algorithm*/ 
time_t end_time = time(NULL); 
cerr <<"Execution Time: "<< (end_time - start_time);

For Java:

long startTime = System.nanoTime();
/*Your algorithm*/
long endTime = System.nanoTime();

long duration = endTime - startTime;
Aniket Inge
  • 25,375
  • 5
  • 50
  • 78
  • but, how can I know the PID of a process or the the name, to use: "ps -ef | grep process name". – edymerchk Oct 18 '12 at 03:43
  • the thing is that I dont have acces to the code, just the class. maybe you are related with the programming contests ACM-ICPC ? I can't modify the algorithm because I don't know what is going to be inside What I'm trying to do is a validation method that besides a response like ACCEPTED or WRONG ANSWSER(I did this just with de java compiler and then use diff to compare the results) give me some measurements like time of excecution time and memory consumption. – edymerchk Oct 18 '12 at 03:54
  • I gave two approaches. For Java you can get the amount of memory currently used by the JVM. Good this is, you can use shell to filter out the output of the program. Similarly with C++. Now I don't know how to measure the amount of memory used by the program AFTER it has executed you can use getpid() function to return the PID of the currently executing process. – Aniket Inge Oct 18 '12 at 03:55
  • oh god@don't have the code. You will need to read this one: http://stackoverflow.com/questions/131303/linux-how-to-measure-actual-memory-usage-of-an-application-or-process – Aniket Inge Oct 18 '12 at 03:57