aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-07-07 07:34:16 +0300
committermax99x <max99x@gmail.com>2011-07-07 07:34:16 +0300
commitd94b2423aef4593ce2b07725e992b7eb25d5f34c (patch)
tree8ea1b5f593d341cc02e202bd2eea2e777c76b49e
parentdedb83b9e15591893e1b30220c721e447518f5d9 (diff)
Added proper clock() test; fixed inverted clock() sign.
-rw-r--r--src/library.js2
-rw-r--r--tests/time/output.txt3
-rw-r--r--tests/time/src.c9
3 files changed, 9 insertions, 5 deletions
diff --git a/src/library.js b/src/library.js
index bf1f28f8..3fb268dc 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1701,7 +1701,7 @@ var Library = {
clock: function() {
if (_clock.start === undefined) _clock.start = new Date();
- return (_clock.start.getTime() - Date.now())*1000;
+ return (Date.now() - _clock.start.getTime()) * 1000;
},
time: function(ptr) {
diff --git a/tests/time/output.txt b/tests/time/output.txt
index ae1fde67..45b7d4bd 100644
--- a/tests/time/output.txt
+++ b/tests/time/output.txt
@@ -33,5 +33,6 @@ asctime: Wed Dec 25 03:22:43 2002
old asctime: Wed Dec 25 03:22:43 2002
new asctime_r: Sat Jul 2 19:33:20 2011
old asctime again: Wed Dec 25 03:22:43 2002
-clock: 0
+clock(start): 1
+clock(end): 1
ctime: 0
diff --git a/tests/time/src.c b/tests/time/src.c
index 3d4da4c2..94eb6a3f 100644
--- a/tests/time/src.c
+++ b/tests/time/src.c
@@ -91,10 +91,13 @@ int main() {
asctime_r(tm_ptr, buffer);
printf("old asctime again: %s", formatted);
- // Verify that clock() is initially 0 and doesn't crash.
- printf("clock: %d\n", clock());
+ // Verify that clock() advances.
+ clock_t start = clock();
+ printf("clock(start): %d\n", start >= 0);
+ while (clock() - start < 50000); // Poor man's sleep().
+ printf("clock(end): %d\n", clock() - start >= 50000);
- // Verify that ctime_r(x, buf) is equivalent to asctime_r(localtime(x), buf2).
+ // Verify that ctime_r(x, buf) is equivalent to asctime_r(localtime(x), buf).
time_t t7 = time(0);
char buffer2[30];
char buffer3[30];