0
t_start = std::chrono::high_resolution_clock::now();
t_end = std::chrono::high_resolution_clock::now();

long t = t_start; //error

Furthermore, I cannot add t_start with t_end.

t_start += t_end; //error
Jalpesh Patel
  • 3,150
  • 10
  • 44
  • 68
Zeeshan Hayat
  • 401
  • 6
  • 13
  • Don't store it as a long. store it as a `std::chrono::high_resolution_clock::time_point`. What are you really trying to do. – Richard Hodges Apr 11 '18 at 08:17
  • 1
    Possible duplicate of [C++ How do I convert a std::chrono::time\_point to long and back](https://stackoverflow.com/questions/31255486/c-how-do-i-convert-a-stdchronotime-point-to-long-and-back) – Cristian Ionescu Apr 11 '18 at 08:18
  • I am trying to calculate wall time for each time I call a function. – Zeeshan Hayat Apr 11 '18 at 08:20
  • 2
    Why do you need to add two time points? The difference between times is what normally matters. Can you explain more about your intended usage? – Red.Wave Apr 11 '18 at 08:22
  • I was using this function for calculating wall time, but for multithreaded environment I want to change it to calculate wall time and cpu time. For cpu time I am using std::clock and for wall time std::chrono micro. For this program, I am calculating both time as I start the program and than just subtract that amount whenever I call this function to calculate both times between void get_wall_time(uintmax_t* wall_time, long* wall_time_ns) { clock_gettime(CLOCK_MONOTONIC, &ts); *wall_time = uintmax_t(ts.wall_time); *wall_time_ns = ts.wall_time_ns; } – Zeeshan Hayat Apr 11 '18 at 08:29
  • Also, becuase I cannot change the type to long I am not sure how to pass the value by reference. the new function looks like this: void get_wall_time(uintmax_t* wall_time, long* wall_time_ns) { c_end = std::clock(); t_end = std::chrono::high_resolution_clock::now(); uintmax_t tt = 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC; long time_span = std::chrono::duration(t_end - t_start).count(); } – Zeeshan Hayat Apr 11 '18 at 08:35
  • Please refrain from writing extensive code in comments. Instead you should edit your question to show the relevant information. – G.M. Apr 11 '18 at 08:38

1 Answers1

0

It doesn't make sense to add two time points, one operand should be a duration. Consider the following sentences:

Add "1523439002.733219701 seconds since 1 Jan 1970" to "1523439842.733219701 seconds since 1 Jan 1970"

Add "500 seconds" to "523439842.733219701 seconds since 1 Jan 1970"

Add "523439842.733219701 seconds since 1 Jan 1970" to "500 seconds"

Add "500 seconds" to "1000 seconds"

From your comments, what you actually want is to pass time points around. Just change the code that accepts longs to accept std::chrono::high_resolution_clock::time_points

Community
  • 1
  • 1
Caleth
  • 52,200
  • 2
  • 44
  • 75