js/src/devtools/vprof/testVprofMT.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/devtools/vprof/testVprofMT.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include <windows.h>
    1.10 +#include <stdio.h>
    1.11 +#include <time.h>
    1.12 +
    1.13 +#include "vprof.h"
    1.14 +
    1.15 +static void cProbe (void* vprofID)
    1.16 +{
    1.17 +    if (_VAL == _IVAR1) _I64VAR1 ++;
    1.18 +    _IVAR1 = _IVAR0;
    1.19 +
    1.20 +    if (_VAL == _IVAR0) _I64VAR0 ++;
    1.21 +    _IVAR0 = (int) _VAL;
    1.22 +
    1.23 +    _DVAR0 = ((double)_I64VAR0) / _COUNT;
    1.24 +    _DVAR1 = ((double)_I64VAR1) / _COUNT;
    1.25 +}
    1.26 +
    1.27 +//__declspec (thread) boolean cv;
    1.28 +//#define if(c) cv = (c); _vprof (cv); if (cv)
    1.29 +//#define if(c) cv = (c); _vprof (cv, cProbe); if (cv)
    1.30 +
    1.31 +#define THREADS 1
    1.32 +#define COUNT 100000
    1.33 +#define SLEEPTIME 0
    1.34 +
    1.35 +static int64_t evens = 0;
    1.36 +static int64_t odds = 0;
    1.37 +
    1.38 +void sub(int val)
    1.39 +{
    1.40 +    int i;
    1.41 +    //_vprof (1);
    1.42 +    for (i = 0; i < COUNT; i++) {
    1.43 +        //_nvprof ("Iteration", 1);
    1.44 +        //_nvprof ("Iteration", 1);
    1.45 +        _vprof (i);
    1.46 +        //_vprof (i);
    1.47 +        //_hprof(i, 3, (int64_t) 1000, (int64_t)2000, (int64_t)3000);
    1.48 +        //_hprof(i, 3, 10000, 10001, 3000000);
    1.49 +        //_nhprof("Event", i, 3, 10000, 10001, 3000000);
    1.50 +        //_nhprof("Event", i, 3, 10000, 10001, 3000000);
    1.51 +        //Sleep(SLEEPTIME);
    1.52 +        if (i % 2 == 0) {
    1.53 +            //_vprof (i);
    1.54 +            ////_hprof(i, 3, 10000, 10001, 3000000);
    1.55 +            //_nvprof ("Iteration", i);
    1.56 +            evens ++;
    1.57 +        } else {
    1.58 +            //_vprof (1);
    1.59 +            _vprof (i, cProbe);
    1.60 +            odds ++;
    1.61 +        }
    1.62 +        //_nvprof ("Iterate", 1);
    1.63 +    }
    1.64 +    //printf("sub %d done.\n", val);
    1.65 +}
    1.66 +
    1.67 +HANDLE array[THREADS];
    1.68 +
    1.69 +static int run (void)
    1.70 +{
    1.71 +    int i;
    1.72 +
    1.73 +    time_t start_time = time(0);
    1.74 +
    1.75 +    for (i = 0; i < THREADS; i++) {
    1.76 +        array[i] = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)sub, (LPVOID)i, 0, 0);
    1.77 +    }
    1.78 +
    1.79 +    for (i = 0; i < THREADS; i++) {
    1.80 +        WaitForSingleObject(array[i], INFINITE);
    1.81 +    }
    1.82 +
    1.83 +    return 0;
    1.84 +}
    1.85 +
    1.86 +int main ()
    1.87 +{
    1.88 +    DWORD start, end;
    1.89 +
    1.90 +    start = GetTickCount ();
    1.91 +    run ();
    1.92 +    end = GetTickCount ();
    1.93 +
    1.94 +    printf ("\nRun took %d msecs\n\n", end-start);
    1.95 +}

mercurial