Menu

Performance Addon for cppcheck vs a cppcheck check

2018-08-29
2018-08-31
  • john borland

    john borland - 2018-08-29

    I was thinking of writing a Performance Addon for cppcheck vs making them cppchecks. My reason for that is given cppchecks low number of false positives and my belief of you should always measure before assuming something will effect your performance.

    I was going to start off with a simple check to see if someone could use sincos(x) over making the two separate calls to sin(x) and cos(x). In most cases gcc will do that for you if turn on -O1, but I thought it would make a good start.

    Also another check to try and see if a volatile variable is being used out side of a mutex. I have scene code in the past where a variable was marked as volatile and then wasn't used in multi-threaded code. Which decrease the number of the optimizations the complier can do with the code using the variable.

    Also another check would be with some of the glibc math routines like pow while ans = pow (x, 3); is not floating point equivalent to ans = x * x * x; in some cases can be alot faster if x cases pow to take the slow path on 64bit systems.

    Any thoughts?

     
  • versat

    versat - 2018-08-30

    volatile is not only used in multi-threaded code. In code for embedded devices it is used to read/write hardware registers/ports for example. It is also used for code to (more) safely clear memory that stores passwords or other sensitive data. So i would be careful with giving hints that a volatile can be removed. There would be many false positives i guess. And they could have serious consequences if someone follows them.

     
  • Daniel Marjamäki

    My reason for that is given cppchecks low number of false positives and my belief of you should always measure before assuming something will effect your performance.

    yes that is true. well I think it is an interesting idea. I do not really see how you can measure it in a good way - but I assume you have a good idea about it. in theory if you make it work well and it's a clean solution I would like to include it in normal cppcheck. but otherwise an addon might be best.

    it would be interesting to see a proof of concept.

    volatile is not only used in multi-threaded code. In code for embedded devices it is used to read/write hardware registers/ports for example.

    Yes. If the message is clear about this and the user can suppress it for embedded systems that is probably ok.

     

    Last edit: Daniel Marjamäki 2018-08-31
  • john borland

    john borland - 2018-08-31

    Yes versat you are very right about volatile. That's what I get for trying to put in some quick examples off the top of my head.

    yes that is true. well I think it is an interesting idea. I do not really see how you can measure it in a good way - but I assume you have a good idea about it. in theory if you make it work well and it's a clean solution I would like to include it in normal cppcheck. but otherwise an addon might be best.

    I wouldn't assume that. I have a few ideas and they are OK at best, but not great. In the end the responsablity is on the owner of the code to test and measure the impact of the changes. That being said I still hope to not give them bad advice.

    I just figure it can't hurt to try and see where the idea takes me.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.