(E-Mail Removed) wrote:

> Stefan Wallentowitz wrote:

> > FOr sure, but a number sais more than thousand words..

> <snip>

> Save the script as sumstat.tcl. To run it, you can type the following:

>

> tclsh sumstat.tcl stat.txt

> <snip>

> Hope this helps. Of course, I'm assuming you're on a platform that has

> grep and tclsh installed. If not, just use my results. But note that

> the statistics above covers C, C++ and Perl code. I was too lazy to

> separate them.
I've modified the sumstat.tcl script to further analyse results:

============================ begin sumstat.tcl script

#! /usr/bin/env tclsh

if {$argc < 1} {

set input stdin

} else {

set input [open $argv "r"]

}

array set numbers {}

while {[eof $input] == 0} {

set line [gets $input]

# extract words:

set line [split $line " "]

foreach n $line {

# get and count the number:

if {[string is integer -strict $n]} {

set n [expr $n] ;# normalise the number

if {[info exists numbers($n)]} {

incr numbers($n)

} else {

set numbers($n) 1

}

}

}

}

if {$input != "stdin"} {

close $input

}

# now we are done processing, print out stats:

set total 0

set bits8 0

set bits16 0

set bits32 0

puts "Literals found:"

foreach n [lsort -integer [array names numbers]] {

puts " $n - $numbers($n) times"

if {$n < 256 && $n > -128} {

incr bits8 $numbers($n)

} elseif {$n < 65536 && $n > -32768} {

incr bits16 $numbers($n)

} else {

incr bits32 $numbers($n)

}

incr total $numbers($n)

}

set percent8 [format "%0.2f" [expr $bits8*100.0/$total]]

set percent16 [format "%0.2f" [expr $bits16*100.0/$total]]

set percent32 [format "%0.2f" [expr $bits32*100.0/$total]]

puts "\nStatistics:"

puts " 8bit numbers - $bits8 ($percent8%)"

puts " 16bit numbers - $bits16 ($percent16%)"

puts " 32bit numbers - $bits32 ($percent32%)"

============================ end script

also, befure I used: grep -r -e "= [0-9]". I now realise that this only

captures assignments and not integers used for other purposes such as a

= b + 12. I also modified the script to get all numbers in the source

code instead of just numbers after the = sign.

I ran this new script with:

grep -r -E "[0-9]+" code_dir/ | tclsh sumstat.tcl

piping the result of grep directly into the script. This simply gets

all lines containing numbers. The new result is obviously much larger

than before and is probably too long to post. The following is the a

snipped version of the result:

Literals found:

-2147483648 - 5 times

-976170042 - 2 times

-823302554 - 1 times

<snip>

-1 - 285 times

0 - 6704 times

1 - 5408 times

2 - 3600 times

3 - 2194 times

4 - 1735 times

<snip>

1936484395 - 1 times

1936484398 - 1 times

2147483647 - 2 times

Statistics:

8bit numbers - 34984 (83.66%)

16bit numbers - 6346 (15.18%)

32bit numbers - 486 (1.16%)