Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed a file name

  • Loading branch information...
commit 1072709f863ae67eeb5b02c0cb884e308e971e51 1 parent 3d2a510
@JumpNotZero authored
Showing with 57 additions and 0 deletions.
  1. +57 −0 timer.c
View
57 timer.c
@@ -0,0 +1,57 @@
+/*
+ * time.c
+ * It measures the running time of a process
+ * This source code is entered into the public domain because it's silly
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+int main(int count, char* arguments[])
+{
+ clock_t start;
+ clock_t end;
+ double elapsed;
+ int exitCode;
+
+ if (count <= 1 || count > 2)
+ {
+ printf("Erroneous arguments specified. Aborting.\n");
+ return EXIT_FAILURE;
+ }
+
+ if (strcmp(arguments[1], "--help") == 0)
+ {
+ printf("Usage: %s [input]\n", arguments[0]);
+ return EXIT_SUCCESS;
+ }
+
+ start = clock();
+ if (start == -1)
+ {
+ printf("Failed to acquire a starting time reference point. Aborting.\n");
+ return EXIT_FAILURE;
+ }
+
+ exitCode = system(arguments[1]);
+ if (exitCode == -1)
+ {
+ printf("An error was encountered when attempting to start the specified process. Aborting.\n");
+ return EXIT_FAILURE;
+ }
+
+ end = clock();
+ if (end == -1)
+ {
+ printf("Failed to acquire an ending time reference point. Aborting.\n");
+ return EXIT_FAILURE;
+ }
+
+ elapsed = ((double)(end - start)) / CLOCKS_PER_SEC;
+
+ printf("%s -> %s in %F second(s) with exit code %d.\n", arguments[0], arguments[1], elapsed, exitCode);
+
+ return EXIT_SUCCESS;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.