• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Improving efficiency of my function

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

For work reasons I'm required to discuss the efficiency of the function below by manually stepping through the code. I needed some pointers as to how to go about that.

Thanks for any suggestions.
 
Bartender
Posts: 10969
87
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first thing that would help is stating the requirements clearly.
You are computing the elapsed time from the start of the week, ie the previous Sunday at 0 a.m..
 
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved thread to C/C++
 
Rancher
Posts: 280
VI Editor C++ Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:The first thing that would help is stating the requirements clearly.


Agree 100%

Carey Brown wrote:You are computing the elapsed time from the start of the week, ie the previous Sunday at 0 a.m..


No, just short of that. He is trying to establish the time (the 'unsigned long' integral equivalent) corresponding to the start of the week. Agree it is trivial to compute the elapsed time from that.

Alex Monari wrote:For work reasons I'm required to discuss the efficiency of the function below by manually stepping through the code. I needed some pointers as to how to go about that.


See if you can come up with your "'unsigned long' integral equivalent" input_time for 'Saturday July 4 23:59:59 2015' and then step through the code. Do you think the function is efficient?
 
Marshal
Posts: 80145
418
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That I think is C++ code because of the bool keyword, not C.
I presume the == and != operators are overloaded on Strings.
I suspect the greatest overhead is in the format time function. What complexity does that run in?
 
Anand Hariharan
Rancher
Posts: 280
VI Editor C++ Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:That I think is C++ code because of the bool keyword, not C.


C introduced bool albeit after C++. It is a 'typedef' and one needs to include <stdbool.h> for it to be usable.

Campbell Ritchie wrote:I presume the == and != operators are overloaded on Strings.


Actually, C does not have a native string type. In C, one uses an array of characters terminated by the NUL character to hold strings. In C++, one has the string class that comes with member functions (substr is one of them) and overloaded operators.

Campbell Ritchie wrote:I suspect the greatest overhead is in the format time function. What complexity does that run in?


The code posted by the OP does not need any while loops. Also, the OP could use a function that does the reverse of 'format_time' (i.e., one that takes the formatted string representation of the time and returns the integral equivalent.
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic