Question for compare or compute CPU and memory consumption.

4 Ansichten (letzte 30 Tage)
Miraboreasu
Miraboreasu am 15 Sep. 2018
Kommentiert: Walter Roberson am 16 Sep. 2018
Hi,
I am compare two algorithms, so I want to know is there any command that can give the compute CPU and memory consumption for two algorithms respectively when I run them?
Thanks!

Antworten (1)

Walter Roberson
Walter Roberson am 15 Sep. 2018
Bearbeitet: Walter Roberson am 15 Sep. 2018
Not exactly. The meaning of "CPU consumption" has not been well defined since the early 1980s when pipelined architectures and speculative execution starting coming into use. There are some people who claim that about the last true significant architecture for which "CPU consumption" was well defined was the Motorola MC68040.
You can time performance using timeit(), but to do it right you need to test several times and even the relative order of tests can affect the results a lot. But it is better than using tick and tock or etime.
You might be tempted to profile execution speed. You will find that the instrumentation that is added to profile execution ends up slowing down execution a lot, and can give you fairly misleading results about performance in situations where the Just In Time compiler (JIT) would normally help significantly.
  2 Kommentare
Miraboreasu
Miraboreasu am 16 Sep. 2018
Thanks, do you have good criterion for test two different algorithms?
Walter Roberson
Walter Roberson am 16 Sep. 2018
Execute each of them with a number of different sizes of inputs, and compare the ratios of the execution times. If the ratios are pretty much noise, then you cannot really tell the algorithms apart. If the ratios start separated but the ratios converge, then you have different "constants" but the algorithms are broadly the same. If the ratios end up pretty much a straight line but increasing at 45 degrees, then the first algorithm is a factor of "N" (the size) more expensive. And so on. If the ratio converges towards zero then plot the reciprocal of the ratio and it probably will not converge to zero.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Fractals finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by