Skip to content

time.h durationToSec seems very inefficient #34

Closed

Description

@nate-jackson

We have been investigating why we can't seem to get lookupTransform to work properly for us, and came across this function.

Instead of doing the big long thing that is going on there:

inline double durationToSec(const tf2::Duration& input){
    int64_t count = input.count();
    int32_t sec, nsec;
    nsec = static_cast<int32_t>(count % 1000000000l);
    sec = static_cast<int32_t>((count - nsec) / 1000000000l);

    double sec_double, nsec_double;
    nsec_double = 1e-9 * static_cast<double>(nsec);
    sec_double = static_cast<double>(sec);
    return sec_double + nsec_double;
  }

couldn't we just do

inline double durationToSec(const tf2::Duration& input){
    return input.count() * 1e-9;
  }

I can't see a reason for the extra stuff that is going on in there.

Activity

  1. wjwwood commented on Jul 13, 2017

    @wjwwood
    Member

    Sounds reasonable to me, it's probably left over from the conversion. @dhood what do you think?

  2. dhood commented on Jul 14, 2017

    @dhood
    Member

    the proposed conversion isn't as accurate. We might still prefer it (since the conversion isn't exact as is), but in that case we'd need to relax the tolerance on the tests (e.g. this one) and disable this test

  3. dhood commented on Jul 14, 2017

    @dhood
    Member

    Here's CI to show what I mean (these tests were run with --retest-until-fail 20 because the reduced accuracy would manifest as a flaky test since it wouldn't fail for all values of 'now'):

    • Linux Build Status
    • Linux-aarch64 Build Status
    • macOS Build Status
    • Windows Build Status
  4. wjwwood commented on Jul 14, 2017

    @wjwwood
    Member

    Ah, @dhood I forgot about that. Perhaps we should put a comment explaining why the nanoseconds are scaled separately.

  5. dhood commented on Jul 14, 2017

    @dhood
    Member

    sure thing: #35

  6. dhood commented on Jul 14, 2017

    @dhood
    Member

    I'll close this because I believe the question has been addressed. if that's not the case feel free to re-open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions