#!/usr/local/bin/python # coding: iso-8859-1 # Copyright © 2008 by Amos Newcombe # # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with this program. If not, see . '''Command-line program to compare running speed of greatest common divisor algorithms to previously reported results. ''' from gcdtest import gcdtest dShalitSorenson = { # previously reported results ('E', 332): 73000, ('E', 830): 357000, ('E', 1661): 1280000, ('E', 3322): 4850000, ('R', 332): 49000, ('R', 830): 201000, ('R', 1661): 660000, ('R', 3322): 2380000, ('L', 332): 49000, ('L', 830): 211000, ('L', 1661): 714000, ('L', 3322): 2640000, } class gcdcompare(gcdtest): # ¤ Metadata sNDefault = '24' # ¤ Creation def options(self): # called by commander.__init__() 'populate the option parser (self.optParser) with options' self.optParser.add_option('-n', dest='sN', default=self.sNDefault, metavar='n', help='use n random numbers for the test, default ' + self.sNDefault ) def ResolveOptions(self): 'Interpret the command line options.' self.sAlg = 'ERL' self.lnBits = [332, 830, 1661, 3322] try : sN = self.opt.sN except AttributeError: sN = self.sNDefault self.nN = nN = int(sN) self.cPairs = nN * (nN-1) / 2 # ¤ Operation def main(self): dResult = self.test() self.texttable(dResult , 9) print self.texttable(dShalitSorenson, 9) if __name__ == '__main__': import sys gcdcompare(sys.argv).main()