Ευχαριστώ
Java - χρονομέτρηση προγράμματος
Java - χρονομέτρηση προγράμματος
Υπάρχει κάποια εντολή στη ξαωα που χρονομετρά το πρόγραμμά που έχεις γράψει??
Ευχαριστώ
Ευχαριστώ
- Einherjar
- Venus Project Founder
- Posts: 3751
- Joined: Tue Jan 27, 2004 4:42 pm
- Academic status: Alumnus/a
- Gender: ♂
- Location: Washington DC, USA
- Contact:
Μπορείς όταν ξεκινά το πρόγραμμα να θέτεις σε μια long μεταβλητή την τιμή System.getCurrentTimeMilis() (ή κάπως έτσι). Πριν ολοκληρωθεί το πρόγραμμα θα ξανακαλέσεις τη συνάρτηση αυτή και η διαφορά των 2 τιμών θα είναι ο χρόνος εκτέλεσης του προγράμματος σε ms
[Better to understand a little than to misunderstand a lot]
- AmmarkoV
- Wow! Terabyte level
- Posts: 2838
- Joined: Thu Nov 04, 2004 2:55 pm
- Gender: ♂
- Location: Reloaded @ Santa Friday
- Contact:
Βασικά αυτό που θα κάνει μάλλον το System.getCurrentTimeMilis() που λές Einherjar είναι ένα call στο GetTickCount του Win32API..
--/ Και μετά λέμε γιατί αργεί η JVM
/--
( The GetTickCount function retrieves the number of milliseconds that have elapsed since Windows was started.
DWORD GetTickCount(VOID))

--/ Και μετά λέμε γιατί αργεί η JVM

( The GetTickCount function retrieves the number of milliseconds that have elapsed since Windows was started.
DWORD GetTickCount(VOID))
- Spoiler: εμφάνιση/απόκρυψη

- AmmarkoV
- Wow! Terabyte level
- Posts: 2838
- Joined: Thu Nov 04, 2004 2:55 pm
- Gender: ♂
- Location: Reloaded @ Santa Friday
- Contact:
Έτσι από περιέργεια
θα φτιάξω 2 προγραμματάκια και θα τα αντιπαραβάλλω..
Μπορεί να έχω άδικο..
ADDED
Δεν γίνεται compile (!)
cannot resolve symbol..
symbol : method getCurrentTimeMilis ()
location: class java.lang.System
long time1=System.getCurrentTimeMilis();
^
1 error
Μάλλον δεν είναι έτσι ακριβώς η εντολή ή δεν έχω κάνει κάποιο package import..
Πάντως υπάρχει και 2η εντολή στο ίδιο το Win32API που λέγεται "GetCurrentTime" και κάνει την ίδια δουλειά με την GetTickCount
The GetCurrentTime function retrieves the number of milliseconds that have elapsed since Windows was started.
DWORD GetCurrentTime(VOID)
Parameters
This function has no parameters.
Return Value
If the function succeeds, the return value is the number of milliseconds that have elapsed since Windows was started.
Remarks
The GetCurrentTime function is identical to the GetTickCount function. Applications should use the GetTickCount function because its name matches more closely what the function does.
The GetCurrentTime and GetMessageTime functions return different times. GetMessageTime returns the Windows time when the given message was created, not the current Windows time.
The internal timer wraps around to zero if Windows is run continuously for approximately 49.7 days
Τεσπα το παρατάω , όρεξη που έχω και εγώ βραδιάτικα..

Μπορεί να έχω άδικο..
ADDED
Δεν γίνεται compile (!)
cannot resolve symbol..
symbol : method getCurrentTimeMilis ()
location: class java.lang.System
long time1=System.getCurrentTimeMilis();
^
1 error
Μάλλον δεν είναι έτσι ακριβώς η εντολή ή δεν έχω κάνει κάποιο package import..
Πάντως υπάρχει και 2η εντολή στο ίδιο το Win32API που λέγεται "GetCurrentTime" και κάνει την ίδια δουλειά με την GetTickCount
The GetCurrentTime function retrieves the number of milliseconds that have elapsed since Windows was started.
DWORD GetCurrentTime(VOID)
Parameters
This function has no parameters.
Return Value
If the function succeeds, the return value is the number of milliseconds that have elapsed since Windows was started.
Remarks
The GetCurrentTime function is identical to the GetTickCount function. Applications should use the GetTickCount function because its name matches more closely what the function does.
The GetCurrentTime and GetMessageTime functions return different times. GetMessageTime returns the Windows time when the given message was created, not the current Windows time.
The internal timer wraps around to zero if Windows is run continuously for approximately 49.7 days
Τεσπα το παρατάω , όρεξη που έχω και εγώ βραδιάτικα..

- Spoiler: εμφάνιση/απόκρυψη

- eso_etoimos
- bit level
- Posts: 25
- Joined: Sat May 01, 2004 12:02 am
- AnINffected
- Gbyte level
- Posts: 1935
- Joined: Fri Jul 30, 2004 7:12 am
- Location: There and Back Again
Το κοίταξα στο api... (έχω το 1.4.2)
Το όνομα της μεθόδου είναι currentTimeMillis και όχι getCurrentTimeMilis.
Χωρίς το get μπροστά δηλαδή.
Μια και πιάσαμε αυτή τη κουβέντα ξέρετε τίποτα προγραμματάκια που να κάνουν ανάλυση πολυπλοκότητας και τα ρέστα;
Το όνομα της μεθόδου είναι currentTimeMillis και όχι getCurrentTimeMilis.
Χωρίς το get μπροστά δηλαδή.
Μια και πιάσαμε αυτή τη κουβέντα ξέρετε τίποτα προγραμματάκια που να κάνουν ανάλυση πολυπλοκότητας και τα ρέστα;
The Analytical Engine has no pretensions to originate anything. It can do whatever we know how to order it to perform (...)
Ada Lovelace
Θέλω και εγώ να παίξω D&D λέμε!!!

Ada Lovelace
Θέλω και εγώ να παίξω D&D λέμε!!!


- Skeftomilos
- bit level
- Posts: 43
- Joined: Fri Mar 04, 2005 8:08 am
- Location: Ν.Κόσμος
Για τη χρονομέτρηση των build-in συναρτήσεων της VB6 είχα χρησιμοποιήσει τη συνάρτηση Timer (returns the number of seconds elapsed since midnight). Όμως η φύση της μέτρησης απαιτούσε τη συχνή κλήση της συνάρτησης αυτής, με συνέπεια τα αποτελέσματα να παραμορφώνονται λόγω του χρόνου κλήσης της συνάρτησης. Με άλλα λόγια η ίδια η Timer αποδείχτηκε αργή! Επιπλέον έδινε και τιμές μικρής ακρίβειας. Τελικά βρέθηκε ότι η GetTickCount ήταν και ακριβέστερη και πολύ ταχύτερη!
Win 98, PentiumII 300mhz
Ξανάκανα τις δοκιμές αργότερα με Win-XP Seleron 2.4, περιμένοντας μία αναλογική μείωση των χρόνων. Τα αποτελέσματα ήταν απρόβλεπτα:
Στον ίδιο υπολογιστή έκανα και σχετικές δοκιμές με τις συναρτήσεις χρόνου του .NET Framework 1.0:
Έκπληξη! Η κλήση της GetTickCount από managed κώδικα είναι πολύ πιο αργή συγκριτικά με τη VB6.
Ελπίζω όλα αυτά να είναι έστω και λίγο χρήσιμα, καθώς δεν έχουν άμεση σχέση με τη Java της $un.
Win 98, PentiumII 300mhz
Code: Select all
Timer (VBA) : 91.300 nsec
Now (VBA) : 100.000 nsec
Date (VBA) : 110.000 nsec
Time (VBA) : 90.000 nsec
Year, Month, Day (VBA) : 3.000 nsec
DatePart (VBA) : 15.500 nsec
DateDiff (VBA) : 26.000 nsec
DateSerial (VBA) : 1.500 nsec
GetTickCount (Win-API) : 160 nsec
Code: Select all
Timer (VBA) : 380 nsec
Now (VBA) : 640 nsec
Date (VBA) : 980 nsec
Time (VBA) : 540 nsec
Year, Month, Day (VBA) : 700 nsec
DatePart (VBA) : 1.200 nsec
DateDiff (VBA) : 2.600 nsec
DateSerial (VBA) : 265 nsec
GetTickCount (Win-API) : 27 nsec
Code: Select all
Microsoft.VisualBasic.DateAndTime.Timer : 168 nsec
Microsoft.VisualBasic.DateAndTime.Now : 54 nsec
Microsoft.VisualBasic.DateAndTime.Today : 124 nsec
System.DateTime.Now : 50 nsec
System.DateTime.Today : 120 nsec
System.DateTime.Now.Ticks : 54 nsec
System.Environment.TickCount : 14 nsec
System.DateTime.Now.Year : 240 nsec
System.DateTime.Now.Month : 250 nsec
System.DateTime.Now.Day : 250 nsec
System.DateTime.IsLeapYear : 22 nsec
System.DateTime.AddDays : 170 nsec
System.DateTime.AddMonths : 880 nsec
System.DateTime.AddYears : 880 nsec
GetTickCount (Win-API) : 365 nsec
Ελπίζω όλα αυτά να είναι έστω και λίγο χρήσιμα, καθώς δεν έχουν άμεση σχέση με τη Java της $un.

The pure and simple truth is rarely pure and never simple. Ο μη νους δε σκέπτεται μη σκέψεις για το τίποτα.
Απο τη κλαση System:
/**
* Returns the current value of the most precise available system
* timer, in nanoseconds.
*
* <p>This method can only be used to measure elapsed time and is
* not related to any other notion of system or wall-clock time.
* The value returned represents nanoseconds since some fixed but
* arbitrary time (perhaps in the future, so values may be
* negative). This method provides nanosecond precision, but not
* necessarily nanosecond accuracy. No guarantees are made about
* how frequently values change. Differences in successive calls
* that span greater than approximately 292 years (2<sup>63</sup>
* nanoseconds) will not accurately compute elapsed time due to
* numerical overflow.
*
* <p> For example, to measure how long some code takes to execute:
* <pre>
* long startTime = System.nanoTime();
* // ... the code being measured ...
* long estimatedTime = System.nanoTime() - startTime;
* </pre>
*
* @return The current value of the system timer, in nanoseconds.
* @since 1.5
*/
public static native long nanoTime();
/**
* Returns the current value of the most precise available system
* timer, in nanoseconds.
*
* <p>This method can only be used to measure elapsed time and is
* not related to any other notion of system or wall-clock time.
* The value returned represents nanoseconds since some fixed but
* arbitrary time (perhaps in the future, so values may be
* negative). This method provides nanosecond precision, but not
* necessarily nanosecond accuracy. No guarantees are made about
* how frequently values change. Differences in successive calls
* that span greater than approximately 292 years (2<sup>63</sup>
* nanoseconds) will not accurately compute elapsed time due to
* numerical overflow.
*
* <p> For example, to measure how long some code takes to execute:
* <pre>
* long startTime = System.nanoTime();
* // ... the code being measured ...
* long estimatedTime = System.nanoTime() - startTime;
* </pre>
*
* @return The current value of the system timer, in nanoseconds.
* @since 1.5
*/
public static native long nanoTime();
Ναι και εμενα μου αρεσε full.Εψαχνα για τις δομες που καναμε τον shakeSort να βαλω και ενα println ετσι για τα τυπικα που να τυπωνει τον χρονο εκτελεσης και εβαζα την currentTimeInMillis αλλα η διαφορα(endTime-startTime) ηταν παντα μηδεν (προφανως :P).Και καθως εριχνα μια ματια σε ολες τις βασικες κλασσης της java στο src.zip τσοουουουπ επεταχτηκε και αυτη χεχε.
Ασχετο: Νεκταριουμ θελω καποια στιγμη συμπυκνωμενη γνωση περι J2EE!!Εχει πολυ πραγμα το βασσαλιδιο και μια συζητησουλα μαζι θα μου γλυτωσει πολυ πολυ χρονο ως γνωστο τσακαλακι επι του θεματος που εισαι :P
Ασχετο: Νεκταριουμ θελω καποια στιγμη συμπυκνωμενη γνωση περι J2EE!!Εχει πολυ πραγμα το βασσαλιδιο και μια συζητησουλα μαζι θα μου γλυτωσει πολυ πολυ χρονο ως γνωστο τσακαλακι επι του θεματος που εισαι :P
- HdkiLLeR
- Venus Project Founder
- Posts: 4356
- Joined: Tue Jan 27, 2004 4:41 pm
- Academic status: Alumnus/a
- Gender: ♂
- Location: New York, NY
- Contact:
Εαν έχεις linux box τρέξε time <prog>
Θα πάρεις κάτι τέτοιο:
real = user + sys
real = συνολικός χρόνος.
user = χρόνος εκτέλεσης εντολών σε user space.
sys = χρόνος εκτέλεσης των system calls.
Είναι απο το OS καταυθείαν απο το process acounting του kernel αλλά δεν το έχω κάνει για java ποτέ για να δώ αποτελέσματα...τώρα που το λές θα το τσεκάρω
Θα πάρεις κάτι τέτοιο:
Code: Select all
real 0m0.008s
user 0m0.003s
sys 0m0.005s
real = συνολικός χρόνος.
user = χρόνος εκτέλεσης εντολών σε user space.
sys = χρόνος εκτέλεσης των system calls.
Είναι απο το OS καταυθείαν απο το process acounting του kernel αλλά δεν το έχω κάνει για java ποτέ για να δώ αποτελέσματα...τώρα που το λές θα το τσεκάρω

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d-->--- s+:+ a- C++(+++) BILS++++$ P--- L++++>+++++ E--- W+++ N+ o+ K w--
O M+ V-- PS++>+++ PE- Y++ PGP++ t+ 5+ X+ R* tv b++ DI- D+ G+++ e+++>++++ h r++ y++
------END GEEK CODE BLOCK------
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity." -- Dennis Ritchie
Version: 3.12
GCS d-->--- s+:+ a- C++(+++) BILS++++$ P--- L++++>+++++ E--- W+++ N+ o+ K w--
O M+ V-- PS++>+++ PE- Y++ PGP++ t+ 5+ X+ R* tv b++ DI- D+ G+++ e+++>++++ h r++ y++
------END GEEK CODE BLOCK------
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity." -- Dennis Ritchie