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 discount levitra purchase

buy cialis for daily use

get levitra online

canada meds viagra

cialis and ketoconazole

canadian pharmacy

generic viagra canadian

cialis and diarrhea

buying propecia

buy dosages levitra

buy cheap levitra

canadian healthcare viagra

buy generic viagra india rx

can i get viagra in mexico

cheapest price propecia cheap

get cialis online

cialis from mexico

discount generic propecia

canada online pharmacy levitra

cheap levitra prescription

mail order levitra

buy propecia without prescription

generic levitra overnight delivery

online generic cialis 100 mg

cheapest propecia prescription

cialis 100 mg generic

cialis for woman

herbal propecia

does generic cialis work

levitra prescription

buy propecia now

cialis daily in canada

generic viagra online

next day viagra

levitra from canadian pharmacy

cialis by mail

buying propecia online

generic propecia fda approved

online cheap viagra

once a day viagra

buy viagra online cheap us

cialis quick shipment

bestellen levitra online

generic viagra canada

indian cialis

buy viagra mexico

buy propecia online from usa pharmacy

cheap viagra online

lowest price on non generic levitra

cialis 20 mg

levitra mail order

cheap canadian viagra

lowest propecia prices

canada levitra

cialis fast delivery

female viagra pills

buy canada levitra

order levitra online

low price levitra

cialis fast delivery usa

cheap order prescription propecia

once daily cialis

cheapest viagra usa

buy cheapest propecia

indian cialis generic

cialis buy overnight

buy propecia on line

levitra viagra online

cialis daily

best price propecia

cialis discounts

get cialis

buy levitra uk

cialis from canada

generic propecia alternative

canadian healthcare

levitra in canada

cialis 50 mg

cheap levitra tablets

buy cheap generic levitra

levitra for sale

canadian healthcare pharmacy

get levitra

buy cialis cannada

levitra viagra cialis

buy cialis online canada

generic levitra online

generic propecia 5mg

cialis 5 mg buy

buy now propecia

cialis strenght mg

buy viagra on line

levitra discount

levitra online no prescription

buy viagra online

buy generic cialis

brand cialis for sale

low cost canadian viagra

cheapest viagra online

natural viagra

canada online pharmacy propecia

bio viagra herbal

buy prescription propecia without

generic levitra cheap

best price for propecia

drug generic propecia

cialis headaches

mail online order propecia

canada viagra generic

low cost propecia

cost of viagra

cialis 5 mg

canadian drugs propecia

cialis en mexico

buy fast propecia

name brand cialis

cialis overnight delivery

lowest price propecia

generic propecia finasteride

buy cialis in usa

buy levitra overnight

lowest priced propecia

lowest propecia prices in canada

best price generic propecia

cheap discount levitra

brand name cialis overnight

buying levitra online

buy viagra germany canadian meds

generic levitra purchase

buy propecia where

cheapest propecia uk

order prescription propecia

canadian online pharmacy cialis

cheap propecia online prescription

cialis 5 mg italia

buy cialis fedex shipping

how to get viagra

how much cialis

generic cialis sale

cheap viagra from uk

cialis overnight

generic viagra 100 mg

50 mg cialis

cialis price in canada

generic levitra vardenafil

buy cialis 5 mg

buy propecia prescriptions online

discount levitra rx

online pharmacy propecia renova

5 mg original brand cialis

best price cialis

ordering cialis gel

buy cialis online uk

levitra in india

genuine cialis pills

cheap viagra canada or india

combine cialis and levitra

canada generic propecia

cialis transdermal

buy can from i propecia who

cialis professional no prescription

lowest cost levitra

low cost levitra

levitra sales uk

discount propecia rx

cialis refractory

buy viagra

cialis cheap us pharmacy

levitra cheap fast

buy cheap generic propecia

levitra tabs

canada viagra

buy cialis without prescription

overnight delivery cialis

canadian propecia rx

discount levitra online

cialis professional 100 mg

buy cialis once daily

for sale levitra

getting cialis from canada

best viagra

buy propecia generic

buy propecia online prescription

best price for generic cialis

buy viagra china

buy generic levitra

canada propecia prescription

get propecia online pharmacy

levitra low price

canadian pharmacy discount code viagra

cheap levitra without prescription

buy branded viagra

i need to buy propecia

canadian viagra and healthcare

buy levitra us

brand name cialis

fda levitra

levitra online sales

ganeric cialis

cialis on women

generic propecia effective

cheap cialis from india

cheap levitra uk

cheap cialis

how strong is 5 mg of cialis

cialis generic 100 mg

cheap propecia no prescription

buy online prescription propecia

online pharmacy propecia viagra

internet pharmacy propecia

levitra mg

levitra online

cialis discount

levitra online us

how much is viagra

cheap cialis soft

cheapest viagra

cost of propecia

buying cialis

canadian pharmacy viagra

best price levitra

canadian viagra

cheap propecia 5mg

how to buy cialis in canada

cialis delivered overnight

levitra 10mg

cheapest overnight cialis

cialis one a day

cheapest propecia sale uk

levitra canadian

indian generic levitra

cost of daily cialis

buy propecia online pharmacy

buy levitra online viagra

cialis next day delivery

next day delivery cialis

order cheap levitra

canadian pharmacy cialis

cialis uk

how much does cialis cost

buy discount viagra

mail order propecia

cialis next day

generic propecia online pharmacy

levitra online prescription

order viagra or levitra

cialis vs levitra

generic cialis next day shipping

levitra buy online

buying cialis soft tabs 100 mg

online viagra gel to buy

online ordering propecia

buy real viagra online

generic cialis from india

canadian viagra india

healthcare canadian pharmacy

online propecia prescriptions

buy levitra vardenafil

cheapest prices for viagra

levitra next day delivery

cheap fast levitra

buying online propecia

obtain viagra without prescription

cheap propecia online

cialis prescription

buy propecia cheap

levitra online overnight delivery

hydrochlorothiazide cialis

levitra pill

generic cialis soft tabs

discount cialis india

brand viagra professional

canadian pharmacies cialis

online cialis

lowest price levitra

generic viagra india

cialis to buy

gele viagra

generic propecia sale

canada viagra pharmacies scam

cialis tablets

mexico pharmacy cialis

discount drug propecia

buy cheap levitra online

cialis price 100 mg

levitra order prescription

lowest price propecia best

cheap prescription propecia

cialis 100 mg

generic levitra canada

generic viagra made in india

levitra where to buy

cialis professional 20 mg

best way to use cialis

cialis soft pills

cialis woman

buy levitra online no prescription

buying generic cialis mexico rx

buy propecia in the uk

daily dosage cialis