Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _GNU_SOURCE
- #include <time.h>
- #include <unistd.h>
- #include <sys/syscall.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- void A(){
- }
- double calculateAverage(double *arr, int len)
- {
- double average=0.00;
- //first sum up all entries
- for(int i=0;i<len;i++)
- {
- average+=arr[i];
- }
- return average;
- }
- double timespec_to_ms(struct timespec *ts)
- {
- return ts->tv_sec*1000.0 + ts->tv_nsec/1000000.0;
- }
- int main(int argc, char **argv)
- {
- struct timespec start_time, end_time;
- if(argc <2)
- {
- printf("You entered less than two arguements\n");
- exit(-10);
- }
- if(argv[1] <0)
- {
- printf("you entered a negative argument\n");
- exit(-1);
- }
- //double *TestArray=malloc(sizeof(double)*atoi(argv[1]));
- //double *TestArray2=malloc(sizeof(double)*atoi(argv[1]));
- //double *TestArray3=malloc(sizeof(double)*atoi(argv[1]));
- //double *TestArray4=malloc(sizeof(double)*atoi(argv[1]));
- // Do empty 1
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time);
- for(int i=0;i<(atoi(argv[1]));i++)
- {
- /* begin timing */
- /*for(int i=0;i<1000000;i++)
- {
- //getpid();
- syscall(SYS_getpid);
- }*/
- /*int errorCount=0;
- for(int i=0;i<1000;i++)
- {
- int pid = fork();
- if (pid == 0) {
- return 0;
- }
- if (pid < 0) {
- printf("ERROR: Fork failed.\n");
- errorCount++;
- }
- wait(0);
- }*/
- A();
- /* end timing */
- //TestArray[i]=(timespec_to_ms(&end_time)-timespec_to_ms(&start_time));
- }
- clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time);
- printf("%f ms\n", timespec_to_ms(&end_time)
- - timespec_to_ms(&start_time));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement