OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2016 The Chromium Authors. All rights reserved. | 3 Copyright 2016 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/value/diagnostics/generic.html"> | 8 <link rel="import" href="/tracing/value/diagnostics/generic.html"> |
9 <link rel="import" href="/tracing/value/histogram.html"> | 9 <link rel="import" href="/tracing/value/histogram.html"> |
10 | 10 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 test('significance', function() { | 221 test('significance', function() { |
222 let boundaries = tr.v.HistogramBinBoundaries.createLinear(0, 100, 10); | 222 let boundaries = tr.v.HistogramBinBoundaries.createLinear(0, 100, 10); |
223 let histA = new tr.v.Histogram( | 223 let histA = new tr.v.Histogram( |
224 '', unitlessNumber_smallerIsBetter, boundaries); | 224 '', unitlessNumber_smallerIsBetter, boundaries); |
225 let histB = new tr.v.Histogram( | 225 let histB = new tr.v.Histogram( |
226 '', unitlessNumber_smallerIsBetter, boundaries); | 226 '', unitlessNumber_smallerIsBetter, boundaries); |
227 | 227 |
228 let dontCare = new tr.v.Histogram('', unitlessNumber, boundaries); | 228 let dontCare = new tr.v.Histogram('', unitlessNumber, boundaries); |
229 assert.strictEqual(dontCare.getDifferenceSignificance(dontCare), | 229 assert.strictEqual(dontCare.getDifferenceSignificance(dontCare), |
230 tr.b.Statistics.Significance.DONT_CARE); | 230 tr.b.math.Statistics.Significance.DONT_CARE); |
231 | 231 |
232 for (let i = 0; i < 100; ++i) { | 232 for (let i = 0; i < 100; ++i) { |
233 histA.addSample(i); | 233 histA.addSample(i); |
234 histB.addSample(i * 0.85); | 234 histB.addSample(i * 0.85); |
235 } | 235 } |
236 | 236 |
237 assert.strictEqual(histA.getDifferenceSignificance(histB), | 237 assert.strictEqual(histA.getDifferenceSignificance(histB), |
238 tr.b.Statistics.Significance.INSIGNIFICANT); | 238 tr.b.math.Statistics.Significance.INSIGNIFICANT); |
239 assert.strictEqual(histB.getDifferenceSignificance(histA), | 239 assert.strictEqual(histB.getDifferenceSignificance(histA), |
240 tr.b.Statistics.Significance.INSIGNIFICANT); | 240 tr.b.math.Statistics.Significance.INSIGNIFICANT); |
241 assert.strictEqual(histA.getDifferenceSignificance(histB, 0.1), | 241 assert.strictEqual(histA.getDifferenceSignificance(histB, 0.1), |
242 tr.b.Statistics.Significance.SIGNIFICANT); | 242 tr.b.math.Statistics.Significance.SIGNIFICANT); |
243 assert.strictEqual(histB.getDifferenceSignificance(histA, 0.1), | 243 assert.strictEqual(histB.getDifferenceSignificance(histA, 0.1), |
244 tr.b.Statistics.Significance.SIGNIFICANT); | 244 tr.b.math.Statistics.Significance.SIGNIFICANT); |
245 }); | 245 }); |
246 | 246 |
247 test('basic', function() { | 247 test('basic', function() { |
248 let hist = new tr.v.Histogram('', unitlessNumber, TEST_BOUNDARIES); | 248 let hist = new tr.v.Histogram('', unitlessNumber, TEST_BOUNDARIES); |
249 assert.equal(hist.getBinForValue(250).range.min, 200); | 249 assert.equal(hist.getBinForValue(250).range.min, 200); |
250 assert.equal(hist.getBinForValue(250).range.max, 300); | 250 assert.equal(hist.getBinForValue(250).range.max, 300); |
251 | 251 |
252 hist.addSample(-1, {foo: new tr.v.d.Generic('a')}); | 252 hist.addSample(-1, {foo: new tr.v.d.Generic('a')}); |
253 hist.addSample(0, {foo: new tr.v.d.Generic('b')}); | 253 hist.addSample(0, {foo: new tr.v.d.Generic('b')}); |
254 hist.addSample(0, {foo: new tr.v.d.Generic('c')}); | 254 hist.addSample(0, {foo: new tr.v.d.Generic('c')}); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 assert.throws(hist.addSample.bind(42, 'foo'), Error); | 371 assert.throws(hist.addSample.bind(42, 'foo'), Error); |
372 }); | 372 }); |
373 | 373 |
374 test('getApproximatePercentile', function() { | 374 test('getApproximatePercentile', function() { |
375 function check(array, min, max, bins, precision) { | 375 function check(array, min, max, bins, precision) { |
376 let boundaries = tr.v.HistogramBinBoundaries.createLinear(min, max, bins); | 376 let boundaries = tr.v.HistogramBinBoundaries.createLinear(min, max, bins); |
377 let hist = new tr.v.Histogram( | 377 let hist = new tr.v.Histogram( |
378 '', tr.b.Unit.byName.timeDurationInMs, boundaries); | 378 '', tr.b.Unit.byName.timeDurationInMs, boundaries); |
379 array.forEach((x) => hist.addSample(x, {foo: new tr.v.d.Generic('x')})); | 379 array.forEach((x) => hist.addSample(x, {foo: new tr.v.d.Generic('x')})); |
380 [0.25, 0.5, 0.75, 0.8, 0.95, 0.99].forEach(function(percent) { | 380 [0.25, 0.5, 0.75, 0.8, 0.95, 0.99].forEach(function(percent) { |
381 let expected = tr.b.Statistics.percentile(array, percent); | 381 let expected = tr.b.math.Statistics.percentile(array, percent); |
382 let actual = hist.getApproximatePercentile(percent); | 382 let actual = hist.getApproximatePercentile(percent); |
383 assert.closeTo(expected, actual, precision); | 383 assert.closeTo(expected, actual, precision); |
384 }); | 384 }); |
385 } | 385 } |
386 check([1, 2, 5, 7], 0.5, 10.5, 10, 1e-3); | 386 check([1, 2, 5, 7], 0.5, 10.5, 10, 1e-3); |
387 check([3, 3, 4, 4], 0.5, 10.5, 10, 1e-3); | 387 check([3, 3, 4, 4], 0.5, 10.5, 10, 1e-3); |
388 check([1, 10], 0.5, 10.5, 10, 1e-3); | 388 check([1, 10], 0.5, 10.5, 10, 1e-3); |
389 check([1, 2, 3, 4, 5], 0.5, 10.5, 10, 1e-3); | 389 check([1, 2, 3, 4, 5], 0.5, 10.5, 10, 1e-3); |
390 check([3, 3, 3, 3, 3], 0.5, 10.5, 10, 1e-3); | 390 check([3, 3, 3, 3, 3], 0.5, 10.5, 10, 1e-3); |
391 check([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0.5, 10.5, 10, 1e-3); | 391 check([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 0.5, 10.5, 10, 1e-3); |
(...skipping 10 matching lines...) Expand all Loading... |
402 check([10000], 0, 10, 10, 10000 - 10); | 402 check([10000], 0, 10, 10, 10000 - 10); |
403 // The result is no more than the bin width away from the real percentile. | 403 // The result is no more than the bin width away from the real percentile. |
404 check([1, 1], 0, 10, 1, 10); | 404 check([1, 1], 0, 10, 1, 10); |
405 }); | 405 }); |
406 | 406 |
407 test('histogramBinBoundaries_addBinBoundary', function() { | 407 test('histogramBinBoundaries_addBinBoundary', function() { |
408 let b = new tr.v.HistogramBinBoundaries(-100); | 408 let b = new tr.v.HistogramBinBoundaries(-100); |
409 b.addBinBoundary(50); | 409 b.addBinBoundary(50); |
410 | 410 |
411 checkBoundaries(b, -100, 50, tr.b.Unit.byName.timeDurationInMs, [ | 411 checkBoundaries(b, -100, 50, tr.b.Unit.byName.timeDurationInMs, [ |
412 tr.b.Range.fromExplicitRange(-Number.MAX_VALUE, -100), | 412 tr.b.math.Range.fromExplicitRange(-Number.MAX_VALUE, -100), |
413 tr.b.Range.fromExplicitRange(-100, 50), | 413 tr.b.math.Range.fromExplicitRange(-100, 50), |
414 tr.b.Range.fromExplicitRange(50, Number.MAX_VALUE) | 414 tr.b.math.Range.fromExplicitRange(50, Number.MAX_VALUE) |
415 ]); | 415 ]); |
416 | 416 |
417 b.addBinBoundary(60); | 417 b.addBinBoundary(60); |
418 b.addBinBoundary(75); | 418 b.addBinBoundary(75); |
419 | 419 |
420 checkBoundaries(b, -100, 75, tr.b.Unit.byName.timeDurationInMs, [ | 420 checkBoundaries(b, -100, 75, tr.b.Unit.byName.timeDurationInMs, [ |
421 tr.b.Range.fromExplicitRange(-Number.MAX_VALUE, -100), | 421 tr.b.math.Range.fromExplicitRange(-Number.MAX_VALUE, -100), |
422 tr.b.Range.fromExplicitRange(-100, 50), | 422 tr.b.math.Range.fromExplicitRange(-100, 50), |
423 tr.b.Range.fromExplicitRange(50, 60), | 423 tr.b.math.Range.fromExplicitRange(50, 60), |
424 tr.b.Range.fromExplicitRange(60, 75), | 424 tr.b.math.Range.fromExplicitRange(60, 75), |
425 tr.b.Range.fromExplicitRange(75, Number.MAX_VALUE) | 425 tr.b.math.Range.fromExplicitRange(75, Number.MAX_VALUE) |
426 ]); | 426 ]); |
427 }); | 427 }); |
428 | 428 |
429 test('histogramBinBoundaries_addLinearBins', function() { | 429 test('histogramBinBoundaries_addLinearBins', function() { |
430 let b = new tr.v.HistogramBinBoundaries(1000); | 430 let b = new tr.v.HistogramBinBoundaries(1000); |
431 b.addLinearBins(1200, 5); | 431 b.addLinearBins(1200, 5); |
432 | 432 |
433 checkBoundaries(b, 1000, 1200, tr.b.Unit.byName.powerInWatts, [ | 433 checkBoundaries(b, 1000, 1200, tr.b.Unit.byName.powerInWatts, [ |
434 tr.b.Range.fromExplicitRange(-Number.MAX_VALUE, 1000), | 434 tr.b.math.Range.fromExplicitRange(-Number.MAX_VALUE, 1000), |
435 tr.b.Range.fromExplicitRange(1000, 1040), | 435 tr.b.math.Range.fromExplicitRange(1000, 1040), |
436 tr.b.Range.fromExplicitRange(1040, 1080), | 436 tr.b.math.Range.fromExplicitRange(1040, 1080), |
437 tr.b.Range.fromExplicitRange(1080, 1120), | 437 tr.b.math.Range.fromExplicitRange(1080, 1120), |
438 tr.b.Range.fromExplicitRange(1120, 1160), | 438 tr.b.math.Range.fromExplicitRange(1120, 1160), |
439 tr.b.Range.fromExplicitRange(1160, 1200), | 439 tr.b.math.Range.fromExplicitRange(1160, 1200), |
440 tr.b.Range.fromExplicitRange(1200, Number.MAX_VALUE) | 440 tr.b.math.Range.fromExplicitRange(1200, Number.MAX_VALUE) |
441 ]); | 441 ]); |
442 }); | 442 }); |
443 | 443 |
444 test('histogramBinBoundaries_addExponentialBins', function() { | 444 test('histogramBinBoundaries_addExponentialBins', function() { |
445 let b = new tr.v.HistogramBinBoundaries(0.5); | 445 let b = new tr.v.HistogramBinBoundaries(0.5); |
446 b.addExponentialBins(8, 4); | 446 b.addExponentialBins(8, 4); |
447 | 447 |
448 checkBoundaries(b, 0.5, 8, tr.b.Unit.byName.energyInJoules, [ | 448 checkBoundaries(b, 0.5, 8, tr.b.Unit.byName.energyInJoules, [ |
449 tr.b.Range.fromExplicitRange(-Number.MAX_VALUE, 0.5), | 449 tr.b.math.Range.fromExplicitRange(-Number.MAX_VALUE, 0.5), |
450 tr.b.Range.fromExplicitRange(0.5, 1), | 450 tr.b.math.Range.fromExplicitRange(0.5, 1), |
451 tr.b.Range.fromExplicitRange(1, 2), | 451 tr.b.math.Range.fromExplicitRange(1, 2), |
452 tr.b.Range.fromExplicitRange(2, 4), | 452 tr.b.math.Range.fromExplicitRange(2, 4), |
453 tr.b.Range.fromExplicitRange(4, 8), | 453 tr.b.math.Range.fromExplicitRange(4, 8), |
454 tr.b.Range.fromExplicitRange(8, Number.MAX_VALUE) | 454 tr.b.math.Range.fromExplicitRange(8, Number.MAX_VALUE) |
455 ]); | 455 ]); |
456 }); | 456 }); |
457 | 457 |
458 test('histogramBinBoundaries_combined', function() { | 458 test('histogramBinBoundaries_combined', function() { |
459 let b = new tr.v.HistogramBinBoundaries(-273.15); | 459 let b = new tr.v.HistogramBinBoundaries(-273.15); |
460 b.addBinBoundary(-50); | 460 b.addBinBoundary(-50); |
461 b.addLinearBins(4, 3); | 461 b.addLinearBins(4, 3); |
462 b.addExponentialBins(16, 2); | 462 b.addExponentialBins(16, 2); |
463 b.addLinearBins(17, 4); | 463 b.addLinearBins(17, 4); |
464 b.addBinBoundary(100); | 464 b.addBinBoundary(100); |
465 | 465 |
466 checkBoundaries(b, -273.15, 100, tr.b.Unit.byName.unitlessNumber, [ | 466 checkBoundaries(b, -273.15, 100, tr.b.Unit.byName.unitlessNumber, [ |
467 tr.b.Range.fromExplicitRange(-Number.MAX_VALUE, -273.15), | 467 tr.b.math.Range.fromExplicitRange(-Number.MAX_VALUE, -273.15), |
468 tr.b.Range.fromExplicitRange(-273.15, -50), | 468 tr.b.math.Range.fromExplicitRange(-273.15, -50), |
469 tr.b.Range.fromExplicitRange(-50, -32), | 469 tr.b.math.Range.fromExplicitRange(-50, -32), |
470 tr.b.Range.fromExplicitRange(-32, -14), | 470 tr.b.math.Range.fromExplicitRange(-32, -14), |
471 tr.b.Range.fromExplicitRange(-14, 4), | 471 tr.b.math.Range.fromExplicitRange(-14, 4), |
472 tr.b.Range.fromExplicitRange(4, 8), | 472 tr.b.math.Range.fromExplicitRange(4, 8), |
473 tr.b.Range.fromExplicitRange(8, 16), | 473 tr.b.math.Range.fromExplicitRange(8, 16), |
474 tr.b.Range.fromExplicitRange(16, 16.25), | 474 tr.b.math.Range.fromExplicitRange(16, 16.25), |
475 tr.b.Range.fromExplicitRange(16.25, 16.5), | 475 tr.b.math.Range.fromExplicitRange(16.25, 16.5), |
476 tr.b.Range.fromExplicitRange(16.5, 16.75), | 476 tr.b.math.Range.fromExplicitRange(16.5, 16.75), |
477 tr.b.Range.fromExplicitRange(16.75, 17), | 477 tr.b.math.Range.fromExplicitRange(16.75, 17), |
478 tr.b.Range.fromExplicitRange(17, 100), | 478 tr.b.math.Range.fromExplicitRange(17, 100), |
479 tr.b.Range.fromExplicitRange(100, Number.MAX_VALUE) | 479 tr.b.math.Range.fromExplicitRange(100, Number.MAX_VALUE) |
480 ]); | 480 ]); |
481 }); | 481 }); |
482 | 482 |
483 test('histogramBinBoundaries_throws', function() { | 483 test('histogramBinBoundaries_throws', function() { |
484 let b0 = new tr.v.HistogramBinBoundaries(-7); | 484 let b0 = new tr.v.HistogramBinBoundaries(-7); |
485 assert.throws(function() { b0.addBinBoundary(-10 /* must be > -7 */); }); | 485 assert.throws(function() { b0.addBinBoundary(-10 /* must be > -7 */); }); |
486 assert.throws(function() { b0.addBinBoundary(-7 /* must be > -7 */); }); | 486 assert.throws(function() { b0.addBinBoundary(-7 /* must be > -7 */); }); |
487 assert.throws(function() { b0.addLinearBins(-10 /* must be > -7 */, 10); }); | 487 assert.throws(function() { b0.addLinearBins(-10 /* must be > -7 */, 10); }); |
488 assert.throws(function() { b0.addLinearBins(-7 /* must be > -7 */, 100); }); | 488 assert.throws(function() { b0.addLinearBins(-7 /* must be > -7 */, 100); }); |
489 assert.throws(function() { b0.addLinearBins(10, 0 /* must be > 0 */); }); | 489 assert.throws(function() { b0.addLinearBins(10, 0 /* must be > 0 */); }); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 assert.deepEqual(merged.summaryOptions.get('percentile'), [0.9]); | 690 assert.deepEqual(merged.summaryOptions.get('percentile'), [0.9]); |
691 | 691 |
692 merged.addHistogram(hist1); | 692 merged.addHistogram(hist1); |
693 | 693 |
694 assert.isTrue(merged.summaryOptions.get('min')); | 694 assert.isTrue(merged.summaryOptions.get('min')); |
695 assert.isTrue(merged.summaryOptions.get('sum')); | 695 assert.isTrue(merged.summaryOptions.get('sum')); |
696 assert.deepEqual(merged.summaryOptions.get('percentile'), [0.9, 0.95]); | 696 assert.deepEqual(merged.summaryOptions.get('percentile'), [0.9, 0.95]); |
697 }); | 697 }); |
698 }); | 698 }); |
699 </script> | 699 </script> |
OLD | NEW |