time-it.c 696 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* Reports run time, in seconds, for a command.
  2. The command argument can have multiple words, but then
  3. it has to be quoted, as for example
  4. time-it "command < file1 > file2"
  5. The time interval resolution is one whole second. */
  6. #include <time.h>
  7. int system ();
  8. int printf ();
  9. int
  10. main (argv, argc)
  11. int argv;
  12. char **argc;
  13. {
  14. time_t t0, t1;
  15. if (argv < 2)
  16. {
  17. printf ("Usage: time-it name_of_program_to_be_timed\n");
  18. exit (1);
  19. }
  20. time (&t0);
  21. /* Wait til the clock changes before starting. */
  22. do
  23. {
  24. time (&t1);
  25. }
  26. while (t1 == t0);
  27. system (argc[1]);
  28. t0 = t1;
  29. time (&t1);
  30. printf ("%ld seconds.\n", t1 - t0);
  31. exit (0);
  32. }