Changeset 3228 for proto/RE


Ignore:
Timestamp:
May 29, 2013, 1:52:28 PM (6 years ago)
Author:
bhull
Message:

Performance script changes

Location:
proto/RE/performance
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • proto/RE/performance/perf.py

    r3144 r3228  
    33import csv
    44import StringIO
     5import os.path
     6import sys
    57
    68def execute(execution):
     9        if not os.path.exists(execution.file.file+'.11'):
     10                file = open(execution.file.file,'r')
     11                contents = file.read()
     12                file.close()
     13                file11 = open(execution.file.file+'.11','w')
     14                for i in range(11):
     15                        file11.write(contents)
     16                file11.close
     17        if not os.path.exists(execution.file.file+'.5'):
     18                file = open(execution.file.file,'r')
     19                contents = file.read()
     20                file.close()
     21                file5 = open(execution.file.file+'.5','w')
     22                for i in range(5):
     23                        file5.write(contents)
     24                file5.close
     25
     26
     27
     28        execute_one(execution,1)
     29        one=execute_one(execution,10)
     30        execution5=Execution(execution.stat, execution.program, File(execution.file.file+'.5',execution.file.description+'.5',execution.file.types), execution.expression)
     31        execute_one(execution5,1)
     32        five=execute_one(execution5,10)
     33        execution11=Execution(execution.stat, execution.program, File(execution.file.file+'.11',execution.file.description+'.11',execution.file.types), execution.expression)
     34        execute_one(execution11,1)
     35        eleven=execute_one(execution11,10)
     36        return (eleven-one)/10,one,five/5,eleven/11
     37
     38
     39
     40
     41def execute_one(execution, count):
    742        redirectoutput= ' > /dev/null 2>&1'
    843        if execution.program=='bitstreams':
     
    1550                call('make -C '+re_home+'output/src/' + redirectoutput,shell=True)
    1651               
    17                 cmd = ['perf stat -x, -o perfoutput -r 5 -e '+ execution.stat+ ' '+re_home+'output/src/re '+ execution.file.file + redirectoutput]
     52                cmd = ['perf stat -x, -o perfoutput -r '+str(count)+' -e '+ execution.stat+ ' '+re_home+'output/src/re '+ execution.file.file + redirectoutput]
    1853                p = Popen(cmd,shell=True)
    1954                p.wait()
    2055        if execution.program=='grep':
    21                 cmd = ['perf stat -x, -o perfoutput -r 5 -e '+ execution.stat+ ' grep -c \'' + execution.expression.expression + '\' '+ execution.file.file + redirectoutput]
     56                cmd = ['perf stat -x, -o perfoutput -r '+str(count)+' -e '+ execution.stat+ ' grep -c -E \'' + execution.expression.expression + '\' '+ execution.file.file + redirectoutput]
    2257                p = Popen(cmd,shell=True)
    2358                p.wait()
     59        if execution.program=='nrgrep':
     60                nrgreplocation='nrgrep-1.0/nrgrep'
     61                cmd = ['perf stat -x, -o perfoutput -r '+str(count)+' -e '+ execution.stat+ ' '+nrgreplocation+' -c \'' + execution.expression.expression + '\' '+ execution.file.file + redirectoutput]
     62                p = Popen(cmd,shell=True)
     63                p.wait()
     64        if execution.program=='agrep':
     65                agreplocation='agrep-3.41/agrep'
     66                cmd = ['perf stat -x, -o perfoutput -r '+str(count)+' -e '+ execution.stat+ ' '+agreplocation+' -c \'' + execution.expression.expression + '\' '+ execution.file.file + redirectoutput]
     67                p = Popen(cmd,shell=True)
     68                p.wait()
     69        output_file = open('perfoutput', 'r')
     70        output = output_file.read()
     71        endpos = output.rfind(execution.stat)-1
     72        startpos=endpos-1
     73        while output[startpos-1].isdigit():
     74                startpos-=1
     75        return int(output[startpos:endpos])
    2476               
    2577
     
    3486
    3587
    36 expressions.append(Expression('A[a-z]*b[a-z]*c', 'A[a-z]*b[a-z]*c', ('plaintext',)))
    37 expressions.append(Expression('<a[ ]href', '<a href', ('html',)))
    38 files.append(File('data/file1.txt','data/file1.txt',('plaintext',)))
    39 files.append(File('data/file2.txt','data/file2.txt',('plaintext',)))
    40 files.append(File('data/file3.txt','data/file3.txt',('plaintext','html')))
    41 files.append(File('data/file4.txt','data/file4.txt',('html',)))
    42 programs = ['bitstreams','grep']
     88
     89
     90
     91#http://sljit.sourceforge.net/regex_perf.html
     92files.append(File('data/mark.txt','data/mark.txt',('regex_perf',)))
     93expressions.append(Expression('Twain', 'Twain', ('regex_perf',)))
     94expressions.append(Expression('^Twain', '^Twain', ('regex_perf',)))
     95expressions.append(Expression('Twain$', 'Twain$', ('regex_perf',)))
     96expressions.append(Expression('Huck[a-zA-Z]+|Finn[a-zA-Z]+', 'Huck[a-zA-Z]+|Finn[a-zA-Z]+', ('regex_perf',)))
     97expressions.append(Expression('a[^x]{20}b', 'a[^x]{20}b', ('regex_perf',)))
     98expressions.append(Expression('Tom|Sawyer|Huckleberry|Finn', 'Tom|Sawyer|Huckleberry|Finn', ('regex_perf',)))
     99expressions.append(Expression('.{0,3}(Tom|Sawyer|Huckleberry|Finn)', '.{0,3}(Tom|Sawyer|Huckleberry|Finn)', ('regex_perf',)))
     100expressions.append(Expression('[a-zA-Z]+ing', '[a-zA-Z]+ing', ('regex_perf',)))
     101expressions.append(Expression('^[a-zA-Z]{0,4}ing[^a-zA-Z]', '^[a-zA-Z]{0,4}ing[^a-zA-Z]', ('regex_perf',)))
     102expressions.append(Expression('[a-zA-Z]+ing$', '[a-zA-Z]+ing$', ('regex_perf',)))
     103expressions.append(Expression('^[a-zA-Z ]{5,}$', '^[a-zA-Z ]{5,}$', ('regex_perf',)))
     104expressions.append(Expression('^.{16,20}$', '^.{16,20}$', ('regex_perf',)))
     105expressions.append(Expression('([a-f](.[d-m].){0,2}[h-n]){2}', '([a-f](.[d-m].){0,2}[h-n]){2}', ('regex_perf',)))
     106expressions.append(Expression('([A-Za-z]awyer|[A-Za-z]inn)[^a-zA-Z]', '([A-Za-z]awyer|[A-Za-z]inn)[^a-zA-Z]', ('regex_perf',)))
     107expressions.append(Expression('"[^"]{0,30}[?!\.]"', '"[^"]{0,30}[?!\.]"', ('regex_perf',)))
     108expressions.append(Expression('Tom.{10,25}river|river.{10,25}Tom', 'Tom.{10,25}river|river.{10,25}Tom', ('regex_perf',)))
     109
     110
     111
     112
     113
     114
     115#http://lh3lh3.users.sourceforge.net/reb.shtml
     116files.append(File('data/howto','howto',('reb',)))
     117expressions.append(Expression('([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?', '([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?', ('reb',)))
     118expressions.append(Expression('([^ @]+)@([^ @]+)', '([^ @]+)@([^ @]+)', ('reb',)))
     119expressions.append(Expression('([0-9][0-9]?)/([0-9][0-9]?)/([0-9][0-9]([0-9][0-9])?)', '([0-9][0-9]?)/([0-9][0-9]?)/([0-9][0-9]([0-9][0-9])?)', ('reb',)))
     120expressions.append(Expression('([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?|([^ @]+)@([^ @]+)', '([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?|([^ @]+)@([^ @]+)', ('reb',)))
     121
     122
     123programs = ['bitstreams','grep','nrgrep','agrep']
    43124stats = ['cycles', 'instructions']
    44125
     126typeargument=False
     127if len(sys.argv)>1:
     128        type=sys.argv[1]
     129        typeargument=True
    45130
    46131for file in files:
     
    50135                        for type2 in expression.types:
    51136                                if type1 == type2:
    52                                         match = True
     137                                        if typeargument:
     138                                                if type1==type:
     139                                                        match = True
     140                                        else:
     141                                                match = True
    53142                if match:
    54143                        for program in programs:
     
    59148
    60149for execution in executions:
    61         execute(execution)
    62         output_file = open('perfoutput', 'r')
    63         output = output_file.read()
    64         endpos = output.rfind(execution.stat)-1
    65         startpos=endpos-1
    66         while output[startpos-1].isdigit():
    67                 startpos-=1
    68         writer.writerow((execution.file.description, execution.expression.description, execution.program, execution.stat, output[startpos:endpos]))
     150        calc,one,five,eleven = execute(execution)
     151        writer.writerow((execution.file.description, execution.expression.description, execution.program, execution.stat, calc,one,five,eleven))
    69152
    70153print csv_output.getvalue()
Note: See TracChangeset for help on using the changeset viewer.