Archive

Posts Tagged ‘average’

Estimating variance when measuring source

October 8th, 2009 Derek-Jones No comments

Yesterday I finally delivered a paper on if/switch usage measurements to the ACCU magazine editor and today I read about a switch statement usage that if common, would invalidate a chunk of my results. Does anything jump out at you in the following snippet?

switch (x)
   {
   case 1:
             {
             z++;
             ...
             break;
             }
...

Yes, those { } delimiting the case-labeled statement sequence. A quick check of my C source benchmarks showed this usage occurring in around 1% of case-labels. Panic over.

What is the statistical significance, i.e., variance, of that 1%? Have I simply measured an unrepresentative sample, what would be a representative sample and what would be the expected variance within a representative sample?

I am interested in commercial software development and so I have selected half a dozen or so largish code bases as my source benchmark, preferably written in a commercial environment even if currently available as Open source. I would prefer this benchmark to be an order of magnitude larger and perhaps I will get around to adding more programs soon.

My if/switch measurements were aimed at finding usage characteristics that varied between the two kinds of selection statements. One characteristic measured was the number of equality tests in the associated controlling expression. For instance, in:

if (x == 1 || x == 2)
   z--;
else if (x == 3)
   z++;

the first controlling expression contains two equality tests and the second one equality test.

Plotting the percentage of equality tests that occur in the controlling expressions of if-if/if-else-if sequences and switch statements we get the following:

Number of quality tests in controlling expression

Do these results indicate that if-if/if-else-if sequences and switch statements differ in the number of equality tests contained in their controlling expressions? If I measured a completely different set of source code, would the results be very different?

To answer this question a probability model is needed. Take as an example the controlling expressions present in an if-if sequence. If each controlling expression is independent of the others, then the probability of two equality tests, for instance, occurring in any of these expressions is constant and thus given a large sample the distribution of two equality tests in the source has a binomial distribution. The same argument can be applied to other numbers of equality tests and other kinds of sequence.

Number of quality tests in controlling expression, with error bars

For each measurement point in the above plot the associated error bars span the square-root of the variance of that point (assuming a binomial distribution, for a normal distribution the length of this span is known as the standard deviation). The error bars overlap suggesting that the apparent difference in percentage of equality tests in each kind of sequence is not statistically significant.

The existence of some dependency between controlling expression equality tests would invalidate this simply analysis, or at least reduce its reliability. I did notice that in a sequence that containing two equality tests, the controlling expression that contained it tended to appear later in the sequence (the reverse of the example given above). Did I notice this because I tend to write this way? A question for another day.

Average distance between two fields

December 2nd, 2008 Derek-Jones No comments

If I randomly pick two fields from an aggregate type definition containing N fields what will be the average distance between them (adjacent fields have distance 1, if separated by one field they have distance 2, separated by two fields they have distance 3 and so on)?

For example, a struct containing five fields has four field pairs having distance 1 from each other, three distance 2, two distance 2, and one field pair having distance 4; the average is 2.

The surprising answer, to me at least, is (N+1)/3.

Proof: The average distance can be obtained by summing the distances between all possible field pairs and dividing this value by the number of possible different pairs.

                  Distance 1  2  3  4  5  6
Number of fields
            4              3  2  1
            5              4  3  2  1
            6              5  4  3  2  1
            7              6  5  4  3  2  1

The above table shows the pattern that occurs as the number of fields in a definition increases.

In the case of a definition containing five fields the sum of the distances of all field pairs is: (4*1 + 3*2 + 2*3 + 1*4) and the number of different pairs is: (4+3+2+1). Dividing these two values gives the average distance between two randomly chosen fields, e.g., 2.

Summing the distance over every field pair for a definition containing 3, 4, 5, 6, 7, 8, … fields gives the sequence: 1, 4, 10, 20, 35, 56, … This is sequence A000292 in the On-Line Encyclopedia of Integer sequences and is given by the formula n*(n+1)*(n+2)/6 (where n = N − 1, i.e., the number of fields minus 1).

Summing the number of different field pairs for definitions containing increasing numbers of fields gives the sequence: 1, 3, 6, 10, 15, 21, 28, … This is sequence A000217 and is given by the formula n*(n + 1)/2.

Dividing these two formula and simplifying yields (N + 1)/3.

www.wenn.com
FireStats icon Powered by FireStatswww.tinynibbles.com brand viagra over the net

canadian online pharmacy cialis

cialis and canada custom

buy cialis online canada

cheapest viagra online

how much does cialis cost

levitra mail order

lowest propecia prices in canada

best price propecia

healthcare canadian pharmacy

buy cialis once daily

brand viagra professional

canadian pharmacy

canada generic propecia

cialis alternative

buy cheap generic levitra

cheap prescription propecia

online propecia prescriptions

buying viagra in canada

generic levitra canada

ordering propecia online

cialis price

canadian healthcare viagra

online cialis

cost of daily cialis

buy can from i propecia who

buy prescription propecia without

buy cialis in usa

cialis soft pills

buy propecia cheap

generic cialis soft tabs

cialis from mexico

buy cheap levitra online

buy cialis for daily use

5 mg daily cialis

cheap propecia 5mg

discount cialis india

buy levitra online from canada

generic levitra vardenafil

levitra online us

cheap levitra prescription

low cost levitra

buying generic propecia

order levitra online

buy propecia where

lowest price propecia

fda levitra

cialis discount

ordering cialis gel

buying generic cialis mexico rx

buy viagra china

buy canada levitra

levitra in canada

best price generic propecia

genuine cialis pills

canada levitra

levitra buy online

levitra sales uk

cialis tablets foreign

cheap propecia online

how much cialis

order generic levitra

natural viagra

cialis professional 100 mg

lowest propecia prices

buy propecia in the uk

canada propecia prescription

levitra prescription

5 mg original brand cialis

levitra tabs

buy 5 mg cialis

cialis price 100 mg

canadian pharmacy viagra

buy levitra online viagra

order cheap levitra

buying propecia

best price for generic cialis

canada viagra

order viagra or levitra

cheapest overnight cialis

cheap viagra from uk

generic levitra purchase

cialis strenght mg

online generic cialis 100 mg

online levitra

indian cialis

best price levitra

info levitra

canada viagra generic

canadian drugs propecia

order prescription propecia

get cialis online

buy generic levitra

online cheap viagra

cheapest price propecia cheap

cheapest propecia sale uk

cheap levitra tablets

cialis 50 mg

bestellen levitra online

canada meds viagra

cheap cialis soft

buy generic viagra india rx

buy real cialis

cialis cheap us pharmacy

discount levitra rx

gele viagra

levitra 10mg

discount levitra purchase

generic viagra 100 mg

cialis uk

cialis 5 mg buy

cheap viagra online

lowest cost levitra

order cheapest propecia online

buying cialis

canadian healthcare pharmacy

brand name cialis

cheap levitra

cialis 5 mg italia

once a day viagra

cialis from canada

best viagra

best way to use cialis

mail online order propecia

buy viagra on line

overnight delivery cialis

canadian healthcare

buy real viagra online

buy propecia online prescription

canadian pharmacy discount code viagra

buy cialis 5 mg

how to get viagra

ganeric cialis

lowest priced propecia

buying cialis soft tabs 100 mg

how to buy cialis in canada

cheap propecia online prescription

levitra online prescription

cheapest propecia uk

overnight delivery viagra

cialis delivered overnight

china viagra

buy cheapest propecia

buy cialis without prescription

50 mg cialis

name brand cialis

discount generic propecia

lowest price on non generic levitra

canada viagra pharmacies scam

buy online prescription propecia

online viagra gel to buy

cialis fast delivery usa

get propecia online pharmacy

cialis online

canadian viagra 50mg

indian viagra

how strong is 5 mg of cialis

levitra discount

generic viagra canada

cialis purchase

order cheap propecia

cheap order prescription propecia

cheap levitra uk

buying levitra online

generic viagra india

best price cialis

generic levitra online

generic propecia sale

lowest price propecia best

cialis overnight

drug generic propecia

levitra now online

buy levitra online no prescription

cialis price in canada

generic cialis next day shipping

buy viagra online

cialis cheap

buy propecia prescriptions online

buy cialis canada

cost of propecia

cialis transdermal

brand cialis for sale

buying online propecia

buy levitra vardenafil

levitra for sale

online pharmacy propecia renova

levitra online sales

levitra where to buy

buy viagra

discount drug propecia

cialis on women

cialis next day delivery

cialis profesional

cialis 100 mg

female viagra pills

buy propecia generic

cialis overnight delivery

low cost canadian viagra

generic viagra made in usa

buy cheap levitra

levitra from canadian pharmacy

cialis to buy

buy levitra uk

cheapest viagra

generic propecia alternative

cialis tablets

discount propecia propecia

order propecia

lowest propecia 1 mg

buy propecia on line

online ordering propecia

canada cheap propecia

cheap propecia uk

cialis en mexico

mail order levitra

cialis professional 20 mg

cialis for woman

generic levitra cheap

cialis refractory

cialis and ketoconazole

cheap viagra canada or india

buy cialis fedex shipping

cialis quick shipment

once daily cialis

buy viagra mexico

internet pharmacy propecia

discount propecia rx

mail order propecia

levitra mg

buy discount viagra

daily dosage cialis

canadian viagra

generic viagra canadian

buy propecia online pharmacy

lowest price levitra

get levitra

levitra cheap fast

generic cialis from india

generic propecia for sale

buy viagra online cheap us

buy propecia online from usa pharmacy

generic propecia finasteride

online propecia uk

cialis buy overnight

buy cialis usa

next day viagra

buy cialis online uk

cheap canadian viagra

i need to buy propecia

cheapest propecia prescription

generic viagra online

mexico levitra

levitra pill

generic levitra overnight delivery

cialis pharmacy

generic propecia 5mg

cheap levitra without prescription

levitra online overnight delivery

how much to buy viagra in pounds

best price for propecia

levitra online no prescription

canada online pharmacy propecia

how to get cialis in canada

next day delivery cialis

cialis daily

cialis dosage mg

indian cialis generic

hydrochlorothiazide cialis

buy levitra overnight

cialis woman

buy propecia without prescription

cost levitra low

cheap discount levitra

canadian pharmacy cialis

levitra viagra online

buying cialis next day delivery

canada online pharmacy levitra

cheap propecia no prescription

cialis professional no prescription

levitra next day delivery

generic cialis sale

cialis generic 100 mg

buy dosages levitra

buy viagra without prescription

cialis by mail

buying propecia online

generic propecia online pharmacy

cialis fast delivery

mexico pharmacy cialis

cialis daily dosage pharmacy

indian generic levitra

cialis daily in canada

generic propecia fda approved

get levitra online

buy generic propecia

buy cialis cannada

cialis next day

cheapest viagra usa

cialis in mexico

buy branded viagra