|
|
/home/brennan/n-sim/OrbisQuartus/shared/test.hGo to the documentation of this file.00001 00014 /* 00015 * Copyright 2007. Los Alamos National Security, LLC. This material 00016 * was produced under U.S. Government contract DE-AC52-06NA25396 for 00017 * Los Alamos National Laboratory (LANL), which is operated by Los 00018 * Alamos National Security, LLC, for the Department of Energy. The 00019 * U.S. Government has rights to use, reproduce, and distribute this 00020 * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, 00021 * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL 00022 * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to 00023 * produce derivative works, such modified software should be clearly 00024 * marked, so as not to confuse it with the version available from LANL. 00025 * 00026 * Additionally, this program is free software; you can redistribute 00027 * it and/or modify it under the terms of the GNU General Public 00028 * License as published by the Free Software Foundation; version 2 of 00029 * the License. Accordingly, this program is distributed in the hope 00030 * it will be useful, but WITHOUT ANY WARRANTY; without even the 00031 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00032 * PURPOSE. See the GNU General Public License for more details. 00033 */ 00034 00035 #include <stdio.h> 00036 #include <stdlib.h> 00037 #include <math.h> 00038 #include <sys/time.h> 00039 #include <errno.h> 00040 00041 00042 struct timeval average_time(struct timeval begin[], 00043 struct timeval end[], int size) 00044 { 00045 int i; 00046 long long secs = 0, usecs = 0; 00047 struct timeval avg; 00048 00049 for (i = 0; i < size; i++) { 00050 long sec_diff, usec_diff; 00051 sec_diff = end[i].tv_sec - begin[i].tv_sec; 00052 usec_diff = end[i].tv_usec - begin[i].tv_usec; 00053 if (usec_diff < 0) { 00054 sec_diff--; 00055 usec_diff = 1000000 + usec_diff; 00056 } 00057 secs += sec_diff; 00058 usecs += usec_diff; 00059 } 00060 00061 avg.tv_sec = secs / size; 00062 avg.tv_usec = usecs / size; 00063 return avg; 00064 } |