This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
What's your favorite profiling tool (for C++)
Instead of do it directly inside the C code, I want a some tool to do it for me. e.g, given some C code, it returns how long time it's was executed. Something like LinqPad and most client that given a SQL-query,it returns how time the query was executed in *conds.
You many try
1)GNU profiler (gprof) for function level profiling
http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html#SEC2
2)For overall time statistics you may use the command,
time
Example
3)You can also try parsing the files in /proc (/proc/[pid]/stat) for a particular process,
proc manual
Related
This question already has answers here:
delay a batch file in under a second?
(7 answers)
Closed 2 years ago.
I was wondering if there is a delay command in a batch file that can delay for less than a second (like 0.2 seconds). As of right now I only know of the timeout (seconds) which can only delay for a minimum of 1 second. I would appreciate any help :-)
As i know, there isn't a very "good" way of doing this. Some might suggest using the ping command, which is actually possible to give miliseconds of delay, but this is using the wrong tool for the wrong place.
It would be must better to write a code in C (or any other languages with this feature) and run it on batch. Try the program at the link below.
https://www.elifulkerson.com/projects/millisleep.php
This question already has answers here:
why MATLAB gpuarray is much slower in just adding two matrices?
(2 answers)
Closed 5 years ago.
If i use any function in the list at the following link:
Run Built-In Functions on a GPU
with the argument being of the type gpuArray instead of array, will the result be computed faster? If the answer is yes, is there some case where it is more convinient to use an array instead of a gpuArray?
It is claimed that this question is a duplicate of this one:
why MATLAB gpuarray is much slower in just adding two matrices?
This is clearly not the case, since I am asking in a general manner, while this is comparing CPU to GPU for a specific code. At most, that link should provide an answer to this question.
According to the official documentation:
Measure and Improve GPU Performance
there exists at least one case where the CPU is more performant than the GPU, so the general answer is that the GPU does not necessarily compute faster:
On the same machine, this code displays the output:
Execution time on CPU = 0.019335
Execution time on GPU = 0.027235
I found this documentation to answer this question and provide an answer to those such as
Best Practices for Improving Performance
Comparison between increasing performance on the CPU and the GPU
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I wonder, why is Flex used even till now as far as I know?
If it is not used now and was used earlier, then also what is the advantage it provided over writing C code directly?
This is what I read about Flex
It takes as its input a text file containing regular expressions, together with the action to be
taken when each expression is matched. It produces an output file that contains C source code
defining a function yylex that is a table-driven implementation of a DFA corresponding to the
regular expressions of the input file. The Flex output file is then compiled with a C compiler to
get an executable.
What is the need of Flex? Is it better than writing directly C programs?
better in terms of execution or speed of code writing?
I am referring this as my source
Compared with writing out a state machine by hand, it certainly takes less code to produce a lexical scanner with flex. It is also much easier to read a flex specification and understand what tokens are recognized by it.
While it is possible to hand-optimize a scanner and beat flex in terms of execution time, it is rarely a good use of programmer time. In most parsing problems, the lexical scan is not the bottleneck, and a small performance improvement will be invisible. Also, the naive use of tools like regular expression libraries is likely to produce code which is both much slower and much harder to maintain.
Nothing has changed in the C language over the last 20 years which would affect either of the above statements.
All of the above is contingent on the programmer having some understanding of how to use the tool and for which problems it is and is not appropriate. As with any toolset.
This question already has answers here:
Are there any solid large integer implementations in C? [closed]
(7 answers)
Closed 8 years ago.
Recently in programming contest in Here, the problem is pretty straight forward but catch is with worst case scenario which we have to handle data of size 10^10000 .
I tried the program in python which is straight forward as i don't have to specify the datatype(It is taken care by the compiler ) but when i tried with C I couldn't find the correct datatype .
(I tried uintmax_t which didn't work out too).
So how to approach very huge type of data's in C ?
There is no built-in datatype in C that can store that big values. You will either have to write your own implementation or use a library. As this is a competition, though the second is not an option. Every now and then similar problems appear and usually the best approach is to use another language e.g. java(as it is usually available on competitions).
This question already has an answer here:
Determining if file has been copied or not in C [closed]
(1 answer)
Closed 9 years ago.
In Windows, if you go to a file's properties it shows the last access time right under the time last modified. This changes when I copy it.
How do I view this in C?
You can use the GetFileTime() function to get it. This MSDN article has more details about file times.
The portable way of getting the last modified timestamp is by using fstat or stat. If you want to go the Windows-only route (by directly calling a Windows API), see #xxbbcc's answer.
See How can I get a file's size in C++? for a short piece of sample code that uses stat/fstat - only change for your purpose is that you'll want to read the time_t st_mtime field.