I'm using gcc for my c programmes. How can I check which method is faster (suppose that I write a code to swap two numbers and I rewrote the same code using bit operator), is there any tool in linux to check the time,performance and space?
C is a procedural, low level, and compiled language. Java is an object-oriented, high level, and interpreted language. Java uses objects, while C uses functions. Java is easier to learn and use because it's high level, while C can do more and perform faster because it's closer to machine code.
But to answer your question, well-written C code will generally run faster than well-written code in other languages because part of writing C code "well" includes doing manual optimizations at a near-machine level.
C is a faster language compared to Python as it is compiled. Python programs are usually slower than C programs as they are interpreted. In C, the type of the various variables must be declared when they are created, and only values of those particular types must be assigned to them.
man gprof should help.
But remember, if you use profiler you should test large number of loops. And you should do it with caching effect counted so at least this should be performed on large enough memory area data with random (but the same) order. Use srandom() / random() for this.
Minimal setup:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With