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

Switching top loop to count operations done in 10 sec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.