simplest tool to measure C program cache hit/miss and cpu time in linux?

后端 未结 4 1449
渐次进展
渐次进展 2020-11-29 16:09

I\'m writing a small program in C, and I want to measure it\'s performance.

I want to see how much time do it run in the processor and how many cache hit+misses has

4条回答
  •  情书的邮戳
    2020-11-29 17:02

    You can also use

    /usr/bin/time -v YourProgram.exe
    

    It will show you all this information:

    /usr/bin/time -v ls
        Command being timed: "ls"
        User time (seconds): 0.00
        System time (seconds): 0.00
        Percent of CPU this job got: 60%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.00
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 4080
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 314
        Voluntary context switches: 1
        Involuntary context switches: 1
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0
    

    You can also use the -f flag to format the output to fit your needs.

    Please, be sure to call this program using it's full path, otherway it will call the 'time' command and that's not what you need...

    Hope this helps!

提交回复
热议问题