Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Any better replacement for these functions

Any better replacement for these functions

Scheduled Pinned Locked Moved C / C++ / MFC
performancecode-review
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anthony_Yio
    wrote on last edited by
    #1

    Hello, I am trying to improve the speed of a function which heavily using these functions. template<class T> T min(const valarray<T>& x); and INT abs( int n ); in math.h and int memcmp( const void *buf1, const void *buf2, size_t count ); Any better functions to be used other than these. Thank you. Sonork 100.41263:Anthony_Yio

    A 1 Reply Last reply
    0
    • A Anthony_Yio

      Hello, I am trying to improve the speed of a function which heavily using these functions. template<class T> T min(const valarray<T>& x); and INT abs( int n ); in math.h and int memcmp( const void *buf1, const void *buf2, size_t count ); Any better functions to be used other than these. Thank you. Sonork 100.41263:Anthony_Yio

      A Offline
      A Offline
      armentage
      wrote on last edited by
      #2

      Try using memmove instead of memcpy. As for abs(), try replacing it with this inline function: inline int myAbs(int n) { if (n < 0) return -n; else return n; } That would be a lot quicker than a function call. There maybe more to the abs function than that, but I don't know the details. As for min(), I've never seen that particular version of it before. If you are doing something thats computationally heavy on prepared data, you could sort the data ahead of time and then just pull out the first element, that'd be your min.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups