]> git.cryptolib.org Git - avr-crypto-lib.git/blob - host/data2wiki.rb
fixing some bugs of performance measurment
[avr-crypto-lib.git] / host / data2wiki.rb
1 #!/usr/bin/ruby
2 # performnce to wiki
3
4 =begin
5     This file is part of the AVR-Crypto-Lib.
6     Copyright (C) 2009  Daniel Otte (daniel.otte@rub.de)
7
8     This program is free software: you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 =end
21
22 =begin
23  === Twister-256 performance === 
24     type:                     hash
25     hashsize (bits):           256
26     ctxsize (bytes):            80
27     blocksize (bits):          512
28     init (cycles):             425
29     nextBlock (cycles):      36535
30     lastBlock (cycles):       8071
31     ctx2hash (cycles):       19431
32
33    text    data     bss     dec     hex filename
34    6801      32       0    6833    1ab1 bin/bmw_c/bmw_small.o
35 =end
36
37 def get_size_string(fsize)
38   str = ''
39   sum = 0
40   lb = fsize.readline()
41   loop do
42     return sum.to_s() +  str if fsize.eof()
43     lb = fsize.readline()
44     m = lb.match(/[\s]*([\w]*)[\s]*([\w]*)[\s]*([\w]*)[\s]*([\w]*)[\s]*([\w]*)[\s]*([\w_\/-]*)/)
45     name = m[6].match(/\/([^\/]*)$/)[1]
46     str += "<br> \n" + name+': '+m[4]
47     sum += m[4].to_i
48   end
49 end
50
51 def process_hashfunction(fin, name, fsize)
52   lb = fin.readline()
53   m = lb.match(/hashsize \(bits\):[\s]*([\d]*)/)
54   if(!m)
55         printf("unexpected string %s\n", lb)
56   end
57   hashsize = m[1].to_i()
58   lb = fin.readline()
59   m = lb.match(/ctxsize \(bytes\):[\s]*([\d]*)/)
60   ctxsize = m[1].to_i()
61   lb = fin.readline()
62   m = lb.match(/blocksize \(bits\):[\s]*([\d]*)/)
63   blocksize = m[1].to_i()
64   lb = fin.readline()
65   m = lb.match(/init \(cycles\):[\s]*([\d]*)/)
66   inittime = m[1].to_i()
67   lb = fin.readline()
68   m = lb.match(/nextBlock \(cycles\):[\s]*([\d]*)/)
69   nextblocktime = m[1].to_i()  
70   lb = fin.readline()
71   m = lb.match(/lastBlock \(cycles\):[\s]*([\d]*)/)
72   lastblocktime = m[1].to_i()
73   lb = fin.readline()
74   m = lb.match(/ctx2hash \(cycles\):[\s]*([\d]*)/)
75   convtime = m[1].to_i()
76   size = get_size_string(fsize)
77   printf("| %20s || %3s || %3s \n| %s \n| %4d || || %4d || %4d ||" +
78          " %6d || %6d || %7.2f || %6d || || || \n|-\n" , 
79         name, $lang, $lang, size, ctxsize, hashsize, blocksize, 
80             inittime, nextblocktime, nextblocktime.to_f/(blocksize/8),
81                 lastblocktime+convtime)
82 end
83
84
85 $handlers = Hash.new
86 $handlers.default = 0
87 $handlers["hashfunction"] = 1 #process_hashfunction
88
89 def process_file(fname)
90   fin = File.open(fname, "r")
91   $lang = "asm"
92   $lang = "C" if fname.match(/_c.txt$/)
93   algo = fname.match(/.([^.]*).txt$/)[1]
94   size_filename = 'size_log/'+algo+'.size'
95   fsize = File.open(size_filename, "r")
96   begin
97     begin
98           if fin.eof()
99                 return
100           end
101       lb = fin.readline()
102     end while !m=lb.match(/=== (.*) performance ===/)
103     name = m[1];
104     lb = fin.readline()
105     m = lb.match(/type:[\s]*([\w]*)/)
106     type = m[1]
107     if $handlers[type] != 0
108     #  handlers[type](fin, name)
109       process_hashfunction(fin, name, fsize)
110     else
111       printf("ERROR: unsupported type: %s !\n", type)
112     end 
113   end while(true)
114   fin.close()
115 end
116
117 for i in (0..ARGV.size-1)
118   process_file(ARGV[i])
119 end
120
121
122
123
124
125
126