Changeset 4d0eb1c


Ignore:
Timestamp:
Nov 18, 2021, 2:49:47 PM (3 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
97d58dc
Parents:
01db301
Message:

Switching top loop to count operations done in 10 sec

Location:
tests/zombies/string-perf
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/zombies/string-perf/Makefile

    r01db301 r4d0eb1c  
    77PERFFLAGS_CXX = -DNDEBUG -O2
    88
    9 #PERFPROGS can include this one, but it's 10x slower than its peers
    10 #       perfexp-cfa-hl-pta-noshare \
    119
    1210PERFPROGS = \
     
    1513        perfexp-cfa-ll-pta-share \
    1614        perfexp-cfa-ll-peq-share \
     15        perfexp-cfa-hl-pta-noshare \
    1716        perfexp-cfa-hl-peq-noshare \
    1817        perfexp-cfa-ll-pta-noshare \
     
    2625
    2726perfexp-cfa-hl-pta-share : prog.cfa $(LIBCFA)
    28         $(CFA) $(PERFFLAGS_CFA) $^ -o $@ -DIMPL_CFA_HL_SHARE -DOP_PLUS_THEN_ASSIGN
     27        $(CFA) $(PERFFLAGS_CFA) $< -o $@ -DIMPL_CFA_HL_SHARE -DOP_PLUS_THEN_ASSIGN
    2928
    3029perfexp-cfa-hl-peq-share : prog.cfa $(LIBCFA)
    31         $(CFA) $(PERFFLAGS_CFA) $^ -o $@ -DIMPL_CFA_HL_SHARE -DOP_PLUSEQ
     30        $(CFA) $(PERFFLAGS_CFA) $< -o $@ -DIMPL_CFA_HL_SHARE -DOP_PLUSEQ
    3231
    3332perfexp-cfa-ll-pta-share : prog.cfa $(LIBCFA)
    34         $(CFA) $(PERFFLAGS_CFA) $^ -o $@ -DIMPL_CFA_LL_SHARE -DOP_PLUS_THEN_ASSIGN
     33        $(CFA) $(PERFFLAGS_CFA) $< -o $@ -DIMPL_CFA_LL_SHARE -DOP_PLUS_THEN_ASSIGN
    3534
    3635perfexp-cfa-ll-peq-share : prog.cfa $(LIBCFA)
    37         $(CFA) $(PERFFLAGS_CFA) $^ -o $@ -DIMPL_CFA_LL_SHARE -DOP_PLUSEQ
     36        $(CFA) $(PERFFLAGS_CFA) $< -o $@ -DIMPL_CFA_LL_SHARE -DOP_PLUSEQ
    3837
    3938perfexp-cfa-hl-pta-noshare : prog.cfa $(LIBCFA)
    40         $(CFA) $(PERFFLAGS_CFA) $^ -o $@ -DIMPL_CFA_HL_NOSHARE -DOP_PLUS_THEN_ASSIGN
     39        $(CFA) $(PERFFLAGS_CFA) $< -o $@ -DIMPL_CFA_HL_NOSHARE -DOP_PLUS_THEN_ASSIGN
    4140
    4241perfexp-cfa-hl-peq-noshare : prog.cfa $(LIBCFA)
    43         $(CFA) $(PERFFLAGS_CFA) $^ -o $@ -DIMPL_CFA_HL_NOSHARE -DOP_PLUSEQ
     42        $(CFA) $(PERFFLAGS_CFA) $< -o $@ -DIMPL_CFA_HL_NOSHARE -DOP_PLUSEQ
    4443
    4544perfexp-cfa-ll-pta-noshare : prog.cfa $(LIBCFA)
    46         $(CFA) $(PERFFLAGS_CFA) $^ -o $@ -DIMPL_CFA_LL_NOSHARE -DOP_PLUS_THEN_ASSIGN
     45        $(CFA) $(PERFFLAGS_CFA) $< -o $@ -DIMPL_CFA_LL_NOSHARE -DOP_PLUS_THEN_ASSIGN
    4746
    4847perfexp-cfa-ll-peq-noshare : prog.cfa $(LIBCFA)
    49         $(CFA) $(PERFFLAGS_CFA) $^ -o $@ -DIMPL_CFA_LL_NOSHARE -DOP_PLUSEQ
     48        $(CFA) $(PERFFLAGS_CFA) $< -o $@ -DIMPL_CFA_LL_NOSHARE -DOP_PLUSEQ
    5049
    5150perfexp-stl-pta : prog.cfa
    52         $(CXX) -xc++ $(PERFFLAGS_CXX) $^ -o $@ -DIMPL_STL -DOP_PLUS_THEN_ASSIGN
     51        $(CXX) -xc++ $(PERFFLAGS_CXX) $< -o $@ -DIMPL_STL -DOP_PLUS_THEN_ASSIGN
    5352
    5453perfexp-stl-peq : prog.cfa
    55         $(CXX) -xc++ $(PERFFLAGS_CXX) $^ -o $@ -DIMPL_STL -DOP_PLUSEQ
     54        $(CXX) -xc++ $(PERFFLAGS_CXX) $< -o $@ -DIMPL_STL -DOP_PLUSEQ
    5655
    5756perfexp-buhr94-pta.o : prog.cfa
    58         $(CXX) -xc++ -c $(PERFFLAGS_CXX) $^ -o $@ -DIMPL_BUHR94 -DOP_PLUS_THEN_ASSIGN
     57        $(CXX) -xc++ -c $(PERFFLAGS_CXX) $< -o $@ -DIMPL_BUHR94 -DOP_PLUS_THEN_ASSIGN
    5958
    6059perfexp-buhr94-peq.o : prog.cfa
    61         $(CXX) -xc++ -c $(PERFFLAGS_CXX) $^ -o $@ -DIMPL_BUHR94 -DOP_PLUSEQ
     60        $(CXX) -xc++ -c $(PERFFLAGS_CXX) $< -o $@ -DIMPL_BUHR94 -DOP_PLUSEQ
    6261
    6362buhr94-string.o:
     
    7776
    7877MEASURE = $(PERFPROGS)
    79 CORPORI = ../corpus-100-*-1.txt
     78CORPORI = corpus-100-*-1.txt
    8079
    81 measurment: $(MEASURE)
     80measurement: $(MEASURE)
    8281        tofile=measurement-`date '+%F--%H-%M-%S'`.csv ; \
    8382        echo $$tofile ; \
     
    8584            for corpus in $(CORPORI) ; do \
    8685                        corpusbody=`cat $$corpus` ; \
    87                         printed=`./$$prog $$corpusbody` ; \
     86                        printed=`./$$prog 100 10 $$corpusbody` ; \
    8887                        echo $$prog,$$corpus,$$printed  >>  $$tofile ; \
    8988                done ; \
  • tests/zombies/string-perf/prog.cfa

    r01db301 r4d0eb1c  
    55  #include <cstdio>
    66  using namespace std;
     7  #define IMPL_CXX
    78
    89#elif defined IMPL_CFA_HL_SHARE
    910  #define IMPL_CFA_HL
     11  #define IMPL_CFA
    1012
    1113#elif defined IMPL_CFA_LL_SHARE
    1214  #define IMPL_CFA_LL
     15  #define IMPL_CFA
    1316
    1417#elif defined IMPL_CFA_HL_NOSHARE
    1518  #define IMPL_CFA_HL
    1619  #define CFA_NOSHARE
     20  #define IMPL_CFA
    1721
    1822#elif defined IMPL_CFA_LL_NOSHARE
    1923  #define IMPL_CFA_LL
    2024  #define CFA_NOSHARE
     25  #define IMPL_CFA
    2126
    2227#elif defined IMPL_BUHR94
     
    2429  #include <cstdio>
    2530  #include "/u0/mlbrooks/usys1/sm/string/StringSharing/src/string.h"
     31  #define IMPL_CXX
    2632
    2733#else
     
    4450#endif
    4551
     52#if defined IMPL_CFA
     53  #include <math.hfa>
     54#elif defined IMPL_CXX
     55  #include <algorithm>
     56  using std::min;
     57#endif
    4658
    4759#include <time.h>
    48 
     60#include <stdlib.h> // atoi
     61#include <string.h> // strlen, only during setup
    4962
    5063#if defined IMPL_STL || defined IMPL_BUHR94
     
    5669#endif
    5770
     71double meanLen(int N, char ** strings) {
     72    int totalLen = 0;
     73    for (int i = 0 ; i < N; i ++) {
     74        totalLen += strlen(strings[i]);
     75    }
     76    return (double)totalLen / (double)N;
     77}
     78
    5879volatile int checkthis = 0;
    5980#define MAYBE( op ) if (checkthis) { op; }
     
    6182int main( int argc, char ** argv ) {
    6283
    63         STRING_SHARING_CONTROL
     84    STRING_SHARING_CONTROL
    6485
    65         enum { NumConcats = 100, Times = 5000000 };
    66         clock_t start, end;
    6786
    68     int corpuslen = argc - 1;
    69     char ** corpus = argv + 1;
     87    const char * usage_args = "ConcatsPerReset ExecTimeSecs Corpus...";
     88    const int static_arg_posns = 3;
     89
     90    int concatsPerReset = -1, execTimeSecs = -1;
     91
     92    switch (min(argc, static_arg_posns)) {
     93      case 3: execTimeSecs = atoi(argv[2]);
     94      case 2: concatsPerReset = atoi(argv[1]);
     95    }
     96
     97    int corpuslen = argc - static_arg_posns;
     98    char ** corpus = argv + static_arg_posns;
     99
     100    if (execTimeSecs < 1 || concatsPerReset < 1 || corpuslen < 1) {
     101      printf("usage: %s %s\n", argv[0], usage_args);
     102      printf("output:\nconcatsPerReset,corpusItemCount,corpusMeanLenChars,concatDoneActualCount,execTimeActualSec\n");
     103      exit(1);
     104    }
     105
     106    double meanCorpusLen = meanLen(corpuslen, corpus);
     107
     108    clock_t start, end_target, end_actual;
    70109
    71110    #if defined IMPL_CFA_LL
    72         string_res x = "foo2";
     111        string_res x = "starter";
    73112        string_res y;
     113      #if defined OP_PLUS_THEN_ASSIGN
    74114        string_res z;
     115      #endif
    75116        #define RESET y = x;
    76117    #else
    77         string x = "foo2";
     118        string x = "starter";
    78119        string y;
    79120        #define RESET y = x;
     
    81122
    82123    start = clock();
    83     for ( volatile unsigned int t = 0; t < Times; t += 1 ) {
     124    end_target = start + CLOCKS_PER_SEC * execTimeSecs;
     125    volatile unsigned int t = 0;
     126    for ( ; t % 100 != 0 || clock() < end_target ; t += 1 ) {
    84127            RESET
    85             for ( volatile unsigned int i = 0; i < NumConcats; i += 1 ) {
     128            for ( volatile unsigned int i = 0; i < concatsPerReset; i += 1 ) {
    86129              MAYBE( PRINT(y) )
    87               char *toAppend = corpus[i%corpuslen];
     130              char *toAppend = corpus[i % corpuslen]; // ? corpus[rand() % corpuslen]
    88131              #if defined OP_PLUS_THEN_ASSIGN && defined IMPL_CFA_LL
    89132                 z = y;
     
    97140            }
    98141    }
    99     end = clock();
    100     double elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
    101     printf("%f sec\n", elapsed);
     142    end_actual = clock();
     143    unsigned int concatsDone = t * concatsPerReset;
     144    double elapsed = ((double) (end_actual - start)) / CLOCKS_PER_SEC;
     145    printf("%d,%d,%f,%d,%f\n", concatsPerReset, corpuslen, meanCorpusLen, concatsDone, elapsed);
    102146
    103147    return 0;
Note: See TracChangeset for help on using the changeset viewer.