Question

i was wondering how i can get the CPU time from the start of a function...

i was wondering how i can get the CPU time from the start of a function and the CPU time of the end of the function and then take both times to figure out the total time. All this needs to be in Seconds and Milliseconds.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you are using C or C++, you will have to include time.h header file.

#include <time.h>

void my_function() {

// Some code logic of the function here

}

int main() {

// assuming you want to calculate the execution time for my_function

clock_t startTime, endTime;

double totalDuration;

startTime = clock();

my_function();

endTime = clock();

totalDuration = (double(endTime - startTime))/ CLOCKS_PER_SEC // this will give you totalDuration in secs

}

totalDuration is all you need. The basic idea is to save time before function call and then after function returns, then subtract both the times and divide by CLOCKS_PER_SEC to get the time.

Please let me know if you need any further assistance. Thanks.

Add a comment
Know the answer?
Add Answer to:
i was wondering how i can get the CPU time from the start of a function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a-) Draw the gantt chart and computecpu waiting time using preeptive-priority algorithm for the cpu I/O...

    a-) Draw the gantt chart and computecpu waiting time using preeptive-priority algorithm for the cpu I/O device is using FCFS. Compute cpu utilization as well. b-) Draw the gantt chart and compute cpu waiting time using round-robin algorithm for the cpu where quantum is 3 milli seconds. Compute cpu utilization as well. comp 214 2019/2020 Summer School Assignment 1 Priority Arrival Time 4 cpu 12 cpu 6. 3 3 P2 2 4 2 4 loane P3 4 ㅋ 8 6...

  • I was wondering if I could get some help on the last program I need to...

    I was wondering if I could get some help on the last program I need to complete for an engineering C++ class. It is a very simple program however there is one part of the problem stumping me. Here is the problem statement . Write a C++ program that reads in from a file two month names, followed by the rainfall amounts for each month in that span of months. These rain amounts are totaled, and then an average for...

  • Hey, i was wondering how i get data from a .txt file and put it into...

    Hey, i was wondering how i get data from a .txt file and put it into an array? We have to create a structure to hold the information(firstname, lastname, and age) on some characters. That character info is stored on a .txt file. Any and all help is greatly appreciated. (We are using Visual studio 2017 if that makes a difference) txt file Bugs Bunny 1940 Elmer Fudd 1933 Porky Pig 1935 Daffy Duck 1937 Tweety Bird 1942 Taz Devil...

  • Question 4 [Points 4] Consider a system running 2 (two)CPU-bound tasks (C1-C2) and 1(one) I/O-bound tasks(I1). I/O bound...

    Question 4 [Points 4] Consider a system running 2 (two)CPU-bound tasks (C1-C2) and 1(one) I/O-bound tasks(I1). I/O bound task issues an I/O operation once every 1millisecond ofCPU. Each I/O operation takes 10milliseconds. Assume that there is only one I/O device (so multiple I/O requests may have to queue). Assume that the context switch takes 1 millisecond. Assume that each CPU-bound requires 20 milliseconds of CPU to complete and each I/O-bound task requires 2millisecondof CPU time. Show through a Ganttt chart...

  • There are three routes I can take to get from school to home. Every day when...

    There are three routes I can take to get from school to home. Every day when I leave, I randomly select which route I will take (i.e. I am equally likely to take each of the three routes). Route 1 takes 3 minutes, Route 2 takes 5 minutes, and Route 3 takes 7 minutes. (a) What is the expected time it will take me to get home? (b) What is the variance of the time it will take me to...

  • Hello, i was wondering how i can use technology to find the probability that the sample...

    Hello, i was wondering how i can use technology to find the probability that the sample mean is less than a certain number. Assume that i have only been given the mean (2.49), the standard deviation (.07), and a random sample of 14, i have been using the interpolating values method up until now but it takes too long, so how can I use technology to get from the values given, to the sample mean of .3032?

  • Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:

    Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:Processburst TimePriorityP1103P211P323P414P552For each of the scheduling algorithms, FCFS, Shortest-Job-First (SJF, non-preemptive), Priority (smaller priority number implies higher scheduling priority), and RR (quantum = 1) do the following.Draw a Gantt chart to show how these processes would be scheduled.Give the turnaround time (total time from the first arrival into ready state until CPU-burst is completed) of each process.Give the waiting time (total time spent in the Ready state) of each process.Give...

  • I am am trying to figure out how to get from the starting benzene ring using...

    I am am trying to figure out how to get from the starting benzene ring using friedel-crafts acylation and getting a double bond on the end, or a halide on the end. The halide can easily be turned into the double bond. We were unable to transcribe this imageCHM all

  • This is relating to a Risk-Neutral Binomial Tree. I was wondering on how do you get...

    This is relating to a Risk-Neutral Binomial Tree. I was wondering on how do you get those values in the stuffs in red circle? (Using the formula given) The Picture is basically the tree with the solution, but I'm trying to find out how they computed or use the formula to get those values ---- Using the formula 1 = [(1+r1-d)/(u - d)], the tree diagram for the risk neutral probabilities derived from the returns to investing in the market...

  • I dont know how to get this code working??? this is my code: # read_running_times.py #...

    I dont know how to get this code working??? this is my code: # read_running_times.py # Chapter 6.2 Page 258 def main(): # Open the video_times.txt file for reading. video_file = open('video_times.txt', 'r') # Initialize an accumulator to 0.0 total = 0.0 # Initialize a variable to keep count of the videos. count = 0 print('Here are the running times for each video:') # Get the values from the file and total them. for line in video_file: # Error 1:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT