Tcl Source Code

Check-in [8ad25ef9eb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:timerate: added dynamic factor by threshold calculation (avoid growing of the execution time if iterations are not consistent, e. g. wax continuously on time)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | sebres-8-6-timerate
Files: files | file ages | folders
SHA3-256: 8ad25ef9ebc8e989cdbaf7a4d8f6d0ca3daa73a5b03763dbc460d308d8e696d1
User & Date: sebres 2019-02-07 21:20:52.246
References
2019-02-12
19:35
cherrypick [8ad25ef9eb] from 8.6 - timerate: added dynamic factor by threshold calculation (avoid gr... check-in: fd80b4356e user: sergey.brester tags: sebres-8-5-timerate
Context
2019-02-13
02:57
merge 8-5-timerate (?max-count?, break possibility, diverse fixes) + windows time-calibration cycle ... check-in: 2f5413a0fb user: sebres tags: sebres-8-6-timerate
2019-02-12
19:35
cherrypick [8ad25ef9eb] from 8.6 - timerate: added dynamic factor by threshold calculation (avoid gr... check-in: fd80b4356e user: sergey.brester tags: sebres-8-5-timerate
2019-02-07
21:20
timerate: added dynamic factor by threshold calculation (avoid growing of the execution time if iter... check-in: 8ad25ef9eb user: sebres tags: sebres-8-6-timerate
15:45
merge 8.6(.9), conflicts resolved check-in: f29f1e9566 user: sergey.brester tags: sebres-8-6-timerate
Changes
Unified Diff Ignore Whitespace Patch
Changes to generic/tclCmdMZ.c.
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307


4308
4309
4310
4311
4312
4313
4314
{
    static 
    double measureOverhead = 0; /* global measure-overhead */
    double overhead = -1;	/* given measure-overhead */
    register Tcl_Obj *objPtr;
    register int result, i;
    Tcl_Obj *calibrate = NULL, *direct = NULL;
    Tcl_WideInt count = 0;	/* Holds repetition count */
    Tcl_WideInt maxms = -0x7FFFFFFFFFFFFFFFL; 
				/* Maximal running time (in milliseconds) */
    Tcl_WideInt threshold = 1;	/* Current threshold for check time (faster
				 * repeat count without time check) */
    Tcl_WideInt maxIterTm = 1;	/* Max time of some iteration as max threshold
				 * additionally avoid divide to zero (never < 1) */


    register Tcl_WideInt start, middle, stop;
#ifndef TCL_WIDE_CLICKS
    Tcl_Time now;
#endif

    static const char *const options[] = {
	"-direct",	"-overhead",	"-calibrate",	"--",	NULL







|


|

|

>
>







4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
{
    static 
    double measureOverhead = 0; /* global measure-overhead */
    double overhead = -1;	/* given measure-overhead */
    register Tcl_Obj *objPtr;
    register int result, i;
    Tcl_Obj *calibrate = NULL, *direct = NULL;
    Tcl_WideUInt count = 0;	/* Holds repetition count */
    Tcl_WideInt maxms = -0x7FFFFFFFFFFFFFFFL; 
				/* Maximal running time (in milliseconds) */
    Tcl_WideUInt threshold = 1;	/* Current threshold for check time (faster
				 * repeat count without time check) */
    Tcl_WideUInt maxIterTm = 1;	/* Max time of some iteration as max threshold
				 * additionally avoid divide to zero (never < 1) */
    unsigned short factor = 50;	/* Factor (4..50) limiting threshold to avoid
				 * growth of execution time. */
    register Tcl_WideInt start, middle, stop;
#ifndef TCL_WIDE_CLICKS
    Tcl_Time now;
#endif

    static const char *const options[] = {
	"-direct",	"-overhead",	"-calibrate",	"--",	NULL
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512





4513








4514


4515
4516
4517
4518
4519
4520
4521
4522
	Tcl_GetTime(&now);
	middle = now.sec; middle *= 1000000; middle += now.usec;
    #endif
	if (middle >= stop) {
	    break;
	}

	/* don't calculate threshold by few iterations, because sometimes
	 * first iteration(s) can be too fast (cached, delayed clean up, etc) */
	if (count < 10) {
	   threshold = 1; continue;
	}

	/* average iteration time in microsecs */
	threshold = (middle - start) / count;
	if (threshold > maxIterTm) {
	    maxIterTm = threshold;





	}








	/* as relation between remaining time and time since last check */


	threshold = ((stop - middle) / maxIterTm) / 4;
	if (threshold > 100000) {	    /* fix for too large threshold */
	    threshold = 100000;
	}
    }

    {
	Tcl_Obj *objarr[8], **objs = objarr;







|
|








>
>
>
>
>
|
>
>
>
>
>
>
>
>
|
>
>
|







4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
	Tcl_GetTime(&now);
	middle = now.sec; middle *= 1000000; middle += now.usec;
    #endif
	if (middle >= stop) {
	    break;
	}

	/* don't calculate threshold by few iterations, because sometimes first
	 * iteration(s) can be too fast or slow (cached, delayed clean up, etc) */
	if (count < 10) {
	   threshold = 1; continue;
	}

	/* average iteration time in microsecs */
	threshold = (middle - start) / count;
	if (threshold > maxIterTm) {
	    maxIterTm = threshold;
	    /* interations seems to be longer */
	    if (threshold > (maxIterTm * 2)) {
		if ((factor *= 2) > 50) factor = 50;
	    } else {
		if (factor < 50) factor++;
	    }
	} else if (factor > 4) {
	    /* interations seems to be shorter */
	    if (threshold < (maxIterTm / 2)) {
		if ((factor /= 2) < 4) factor = 4;
	    } else {
		factor--;
	    }
	}
	/* as relation between remaining time and time since last check,
	 * maximal some % of time (by factor), so avoid growing of the execution time
	 * if iterations are not consistent, e. g. wax continuously on time) */
	threshold = ((stop - middle) / maxIterTm) / factor + 1;
	if (threshold > 100000) {	    /* fix for too large threshold */
	    threshold = 100000;
	}
    }

    {
	Tcl_Obj *objarr[8], **objs = objarr;