473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

analyzing C code?

Hi,

I am making changes to a few modules of code and wish to test to see
if my changes have made any increases in memory utilization, execution
speed etc... The code is part of a server so lots of other stuff has
to be run AFAIK to test my code (all the server modules). Anyone know
exactly how I can test my code? Ideally I can make a writeup which
says something like, "My changes resulted in functions foo and bar
showed a N% reduction in memory usage and ran M% faster."

Thanks,
Zach

Feb 1 '07 #1
12 1623
On Feb 1, 1:31 pm, "Zach" <net...@gmail.comwrote:
Hi,

I am making changes to a few modules of code and wish to test to see
if my changes have made any increases in memory utilization, execution
speed etc... The code is part of a server so lots of other stuff has
to be run AFAIK to test my code (all the server modules). Anyone know
exactly how I can test my code? Ideally I can make a writeup which
says something like, "My changes resulted in functions foo and bar
showed a N% reduction in memory usage and ran M% faster."

Thanks,
Zach
Personally, every single module of code I write gets a small custom
program
to test the module for correctness (no less than 100% code coverage)
and a small custom program to test for speed (the program just churns
through a ton of essentially random input and prints execution time
statistics). I don't actually test for memory usage, purely because I
try
to program in an extremely explicit style to make it obvious how much
memory is being used.

Combine this with a revision control system and you can essentially
track performance (and correctness) statistics of every code revision.

I feel the style of program shouldn't ever affect ability to test it.
If the
program is too complex to test properly, re-architecture the program
into smaller, individually testable parts.

I'm not sure I've really answered your question.

MC

Feb 1 '07 #2
"Zach" <ne****@gmail.comwrites:
I am making changes to a few modules of code and wish to test to see
if my changes have made any increases in memory utilization, execution
speed etc... The code is part of a server so lots of other stuff has
to be run AFAIK to test my code (all the server modules). Anyone know
exactly how I can test my code? Ideally I can make a writeup which
says something like, "My changes resulted in functions foo and bar
showed a N% reduction in memory usage and ran M% faster."
Standard C doesn't provide a way to measure total memory usage, and
only relatively crude ways to measure speed (see the clock()
function). But many systems provide various kinds of profilers that
will perform these measurements for you. Try a newsgroup that deals
with your operating system, or search for "profiler" in your system's
documentation.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 1 '07 #3
"Zach" <ne****@gmail.comwrote in
I am making changes to a few modules of code and wish to test to see
if my changes have made any increases in memory utilization, execution
speed etc... The code is part of a server so lots of other stuff has
to be run AFAIK to test my code (all the server modules). Anyone know
exactly how I can test my code? Ideally I can make a writeup which
says something like, "My changes resulted in functions foo and bar
showed a N% reduction in memory usage and ran M% faster."
There is no easy way of doing it. As Zach said, it may be possible to
isolate your modules and test them. However you really want to know how it
performs in the server. Beyond a certain level of complexity, it becomes
impossible to control the other allocations a big program makes, and so it
is not sensible to simply run with the new and the old versions and compare.
Feb 1 '07 #4
Zach wrote:
>
I am making changes to a few modules of code and wish to test to
see if my changes have made any increases in memory utilization,
execution speed etc... The code is part of a server so lots of
other stuff has to be run AFAIK to test my code (all the server
modules). Anyone know exactly how I can test my code? Ideally I
can make a writeup which says something like, "My changes
resulted in functions foo and bar showed a N% reduction in
memory usage and ran M% faster."
Just examine the assembly language output of the compiler. This is
system specific and thus OT here. A newsgroup that deals with your
system can give more accurate answers.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Feb 2 '07 #5
CBFalconer <cb********@yahoo.comwrites:
Zach wrote:
I am making changes to a few modules of code and wish to test to
see if my changes have made any increases in memory utilization,
execution speed etc... The code is part of a server so lots of
other stuff has to be run AFAIK to test my code (all the server
modules). Anyone know exactly how I can test my code? Ideally I
can make a writeup which says something like, "My changes
resulted in functions foo and bar showed a N% reduction in
memory usage and ran M% faster."

Just examine the assembly language output of the compiler. This is
system specific and thus OT here. A newsgroup that deals with your
system can give more accurate answers.
I would think that measuring the actual performance of the program
would be much more definitive than examining the assembly language,
unless you happen to know the timings of all the machine's
instructions *including* memory caching effets.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 2 '07 #6
ar**********@googlemail.com wrote:
I feel the style of program shouldn't ever affect ability to test it.
If the
program is too complex to test properly, re-architecture the program
into smaller, individually testable parts.

I'm not sure I've really answered your question.

MC
I think your answer was a great one.
Feb 2 '07 #7
"Zach" <ne****@gmail.comwrites:
Hi,

I am making changes to a few modules of code and wish to test to see
if my changes have made any increases in memory utilization, execution
speed etc... The code is part of a server so lots of other stuff has
to be run AFAIK to test my code (all the server modules). Anyone know
exactly how I can test my code? Ideally I can make a writeup which
says something like, "My changes resulted in functions foo and bar
showed a N% reduction in memory usage and ran M% faster."

Thanks,
Zach
You need to use a profiler. Google will help.
Feb 2 '07 #8
On Feb 1, 10:38 am, artifact....@googlemail.com wrote:
>
Personally, every single module of code I write gets a small custom
program
to test the module for correctness (no less than 100% code coverage)
and a small custom program to test for speed (the program just churns
through a ton of essentially random input and prints execution time
statistics)
Hi,

Could you include some sample code and some sample test code you'd use
to test it. Thanks.

Zach

Feb 3 '07 #9
On Feb 3, 12:20 pm, "Zach" <net...@gmail.comwrote:
On Feb 1, 10:38 am, artifact....@googlemail.com wrote:
Personally, every single module of code I write gets a small custom
program
to test the module for correctness (no less than 100% code coverage)
and a small custom program to test for speed (the program just churns
through a ton of essentially random input and prints execution time
statistics)

Hi,

Could you include some sample code and some sample test code you'd use
to test it. Thanks.

Zach
Well, as I said, the programs are custom programs and are therefore
specific to whatever code is being tested. Here is a contrived example
to test the standard strlen() function:

#include <string.h>
#include <stdio.h>

static const struct {
const char *str;
unsigned long exp;
} tests[] = {
{ "string1", 7 },
{ "string2", 7 },
{ "str\0ing", 3 },
};
static const unsigned long size = sizeof(tests) / sizeof(tests[0]);

int main()
{
unsigned long ind;
unsigned long len;
unsigned long exp;

for (ind = 0; ind < size; ++ind) {
len = strlen(tests[ind].str);
exp = tests[ind].exp;
if (len != exp) {
printf("[%lu] %lu != %lu\n", ind, len, exp);
return 1;
}
printf("[%lu] %lu\n", ind, len);
}
return 0;
}

As you can see it's generally a case of passing input to
code and making sure the code generates the expected
output. I usually use a mix of random and maliciously
crafted input to try to get code to misbehave. Keeping
input in a list as shown makes it easy to work out exactly
where code is misbehaving as, for example, one can say
"'t_strlen:2' fails on Solaris" and easily find out exactly
what the offending input was.

(No, test 2 doesn't fail on Solaris, it's just an example).

In production code, I have one of these programs per
module and the tests are run from a Makefile target
as part of the build.

MC

Feb 3 '07 #10
On Feb 3, 8:21 am, artifact....@googlemail.com wrote:
[...]

Hi MC,

I see. Thanks for the example. Should one do this only for complex
code and/or code they think could have problems or should it be done
even for more trivial programs one thinks they have inspected
rigorously already (visual auditing no test cases etc..)?

Zach
Feb 4 '07 #11
Zach wrote:
On Feb 3, 8:21 am, artifact....@googlemail.com wrote:
[...]

Hi MC,

I see. Thanks for the example. Should one do this only for complex
code and/or code they think could have problems or should it be done
even for more trivial programs one thinks they have inspected
rigorously already (visual auditing no test cases etc..)?
Always have tests. If you get into the habit of witting the tests
first, you will save your self a lot of pain.

--
Ian Collins.
Feb 4 '07 #12
On Feb 4, 2:19 pm, Ian Collins <ian-n...@hotmail.comwrote:
>
Always have tests. If you get into the habit of witting the tests
first, you will save your self a lot of pain.
Ok, will do.

Zach

Feb 4 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Virginia | last post by:
We have a product that runs on Oracle. The version of Oracle I'm working with is 8.1.7. I should also note that I'm relatively new to Oracle. I'm troubleshooting one particular database that is...
0
by: Scott Robert Ladd | last post by:
The latest version of Acovea uses XML configuration files to increase its flexibility. Using a custom benchmark suite, I tested GCC 3.4 for 32-bit Intel Pentium 4 and 64-bit AMD Opteron systems,...
0
by: bj daniels | last post by:
From a Microsoft article, I got some basic information on using sql techniques to read a csv file - I am using the code below, which does work. Unfortuneately, when I try to make the sql...
0
by: Joe Ross | last post by:
(Apologies in advance if there is a better forum for asking advice on this topic). Our ASP.NET application occasionally starts spitting out OutOfMemory exceptions. When this happens, the memory...
2
by: Greg Stark | last post by:
I have a query that is taking too long when run from a larger plpgsql function (40-50s). However when I explain analyze it under psql it runs fine (4-5s). This is with the same parameters, and I've...
3
by: Adman | last post by:
Hi all... At my work, we have a large number of dlls. Each dll is typically a single class, and each class has any number of methods in it. We have "core" objects that generally contain...
8
by: zakaria2710 | last post by:
Question a)Explain what process are being carried out by each method b)Test this code on your system and report the outcome of your tests in a systematic manner.You need to provide rationale for...
4
by: John Nagle | last post by:
I'm printing out each entry in "gc.garbage" after a garbage collection in DEBUG_LEAK mode, and I'm seeing many entries like <cell at 0x00F7C170: function object at 0x00FDD6B0> That's the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.