DiscoveryVIP / Diagnostics AcademyHelp Center

40. Optimization verification

Module 8 · approximately 20 minutes

Open Interactive Lesson

Discover → Predict → Understand

What evidence would distinguish the actual cause of optimization verification from a plausible guess?

An optimization is not successful if it changes the required behavior. Compare independent correctness results before comparing timings, then check whether the change is larger than normal variation. This exact regression calculation works on supplied samples and an explicit tolerance. It does not fabricate browser measurements or guarantee field improvement.

Median
The middle value of sorted samples, or the mean of the two middle values.
Warm-up
Unreported preparation runs intended to reduce first-run effects; not a guarantee that noise is gone.

Working diagnostic operation

An optimization is not successful if it changes the required behavior. Compare independent correctness results before comparing timings, then check whether the change is larger than normal variation. This exact regression calculation works on supplied samples and an explicit tolerance. It does not fabricate browser measurements or guarantee field improvement.

// Controlled lesson program. Read evidence labels; no remote site is inspected.
const E=require("./engine.js");
function feature(input){
  return E.regression(input).regression;
}
const input={
  "before": [
    10,
    10,
    10
  ],
  "after": [
    12,
    12,
    12
  ],
  "tolerance": 5,
  "equivalent": true
};
Promise.resolve().then(()=>feature(input)).then(value=>{
  console.log(JSON.stringify(value));
}).catch(error=>console.log("ERROR: "+error.message));

Exact independently stated expected output

[
  "true"
]

Controlled alternative input

Change one prepared condition, predict and inspect the exact resulting evidence.

// Controlled lesson program. Read evidence labels; no remote site is inspected.
const E=require("./engine.js");
function feature(input){
  return E.regression(input).regression;
}
const input={
  "before": [
    10,
    10,
    10
  ],
  "after": [
    9,
    9,
    9
  ],
  "tolerance": 5,
  "equivalent": true
};
Promise.resolve().then(()=>feature(input)).then(value=>{
  console.log(JSON.stringify(value));
}).catch(error=>console.log("ERROR: "+error.message));

Exact independently stated expected output

[
  "false"
]

Boundary or transfer experiment

Verify the edge case or independent application of this operation.

// Controlled lesson program. Read evidence labels; no remote site is inspected.
const E=require("./engine.js");
function feature(input){
  return E.regression(input).regression;
}
const input={
  "before": [
    10
  ],
  "after": [
    20
  ],
  "tolerance": 5,
  "equivalent": false
};
Promise.resolve().then(()=>feature(input)).then(value=>{
  console.log(JSON.stringify(value));
}).catch(error=>console.log("ERROR: "+error.message));

Exact independently stated expected output

[
  "false"
]

Executable independent contract

The program checks an authored expected value rather than assuming successful execution proves correctness.

// Controlled lesson program. Read evidence labels; no remote site is inspected.
const E=require("./engine.js");
function feature(input){
  return E.regression(input).regression;
}
const input={
  "before": [
    10,
    10,
    10
  ],
  "after": [
    12,
    12,
    12
  ],
  "tolerance": 5,
  "equivalent": true
};
Promise.resolve().then(()=>feature(input)).then(value=>{
  const expected=true;
  if(JSON.stringify(value)!==JSON.stringify(expected))throw Error("Independent contract failed");
  console.log("Contract verified");
}).catch(error=>console.log("ERROR: "+error.message));

Exact independently stated expected output

[
  "Contract verified"
]

Reproducible diagnostic defect

The code returns a conclusion wrapper instead of the required independently verified result. An unsupported claim is not a completed investigation.

// Controlled lesson program. Read evidence labels; no remote site is inspected.
const E=require("./engine.js");
function feature(input){
  return {claim:"Unverified diagnostic conclusion",evidence:input};
}
const input={
  "before": [
    10,
    10,
    10
  ],
  "after": [
    12,
    12,
    12
  ],
  "tolerance": 5,
  "equivalent": true
};
Promise.resolve().then(()=>feature(input)).then(value=>{
  console.log(JSON.stringify(value));
}).catch(error=>console.log("ERROR: "+error.message));

Exact independently stated expected output

[
  "{\"claim\":\"Unverified diagnostic conclusion\",\"evidence\":{\"before\":[10,10,10],\"after\":[12,12,12],\"tolerance\":5,\"equivalent\":true}}"
]

Important source operations

Line 1: // Controlled lesson program. Read evidence labels; no remote site is inspected.
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 2: const E=require("./engine.js");
Load the supplied deterministic diagnostic helpers; no browser privilege or remote inspection is granted.
Line 3: function feature(input){
Implement the specific observable operation independently of the interface.
Line 4: return E.regression(input).regression;
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 5: }
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 6: const input={
Declare reproducible fictional input and its units.
Line 7: "before": [
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 8: 10,
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 9: 10,
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 10: 10
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 11: ],
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 12: "after": [
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 13: 12,
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 14: 12,
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 15: 12
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 16: ],
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 17: "tolerance": 5,
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 18: "equivalent": true
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 19: };
An optimization is not successful if it changes the required behavior. Inspect the precise value relationship on this line.
Line 20: Promise.resolve().then(()=>feature(input)).then(value=>{
Execute the operation and handle asynchronous completion where relevant.
Line 21: console.log(JSON.stringify(value));
Observe actual execution output and compare it with the independent expected contract.
Line 22: }).catch(error=>console.log("ERROR: "+error.message));
Observe actual execution output and compare it with the independent expected contract.

Build → Test

Repair the actual source so the independently expected output is true. Explain why the faulty operation did not establish the intended diagnostic conclusion.

Hint 1

Compare the first actual mismatch with the independent expected result.

Hint 2

Inspect the changed boundary/operator or the diagnostic evidence source. The code returns a conclusion wrapper instead of the required independently verified result. An unsupported claim is not a completed investigation.

Hint 3

Use the complete reference only after explaining the defect. Restore the required operation and add a different input.

Common mistakes and boundaries

Confusing a simulation, imported record or one local observation with a verified production performance result.

Use only controlled local content or sanitized authorized imports. No CORS bypass, remote inspection, privileged breakpoint control or complete accessibility certification is implied.

Explain → Reflect → Extend

Identify the evidence kind, units, assumptions and actual verification. Which part still needs a real user, browser tool or production measurement?

Change one relevant variable, write the expected behavior first, then test the result and retain the original baseline.

Three optional AI learning prompts

Explain This Diagnostic Concept
Explain This Diagnostic Concept
Lesson: Optimization verification
Source:
// Controlled lesson program. Read evidence labels; no remote site is inspected.
const E=require("./engine.js");
function feature(input){
  return E.regression(input).regression;
}
const input={
  "before": [
    10,
    10,
    10
  ],
  "after": [
    12,
    12,
    12
  ],
  "tolerance": 5,
  "equivalent": true
};
Promise.resolve().then(()=>feature(input)).then(value=>{
  console.log(JSON.stringify(value));
}).catch(error=>console.log("ERROR: "+error.message));

Expected:
true
An AI explanation is a hypothesis. Explain the operation, identify missing evidence, propose controlled tests and respect browser/security boundaries. Do not claim to have measured or remotely inspected a site.
Help Me Investigate and Implement a Fix
Help Me Investigate and Implement a Fix
Lesson: Optimization verification
Source:
// Controlled lesson program. Read evidence labels; no remote site is inspected.
const E=require("./engine.js");
function feature(input){
  return E.regression(input).regression;
}
const input={
  "before": [
    10,
    10,
    10
  ],
  "after": [
    12,
    12,
    12
  ],
  "tolerance": 5,
  "equivalent": true
};
Promise.resolve().then(()=>feature(input)).then(value=>{
  console.log(JSON.stringify(value));
}).catch(error=>console.log("ERROR: "+error.message));

Expected:
true
An AI explanation is a hypothesis. Explain the operation, identify missing evidence, propose controlled tests and respect browser/security boundaries. Do not claim to have measured or remotely inspected a site.
Review My Evidence and Verify the Change
Review My Evidence and Verify the Change
Lesson: Optimization verification
Source:
// Controlled lesson program. Read evidence labels; no remote site is inspected.
const E=require("./engine.js");
function feature(input){
  return E.regression(input).regression;
}
const input={
  "before": [
    10,
    10,
    10
  ],
  "after": [
    12,
    12,
    12
  ],
  "tolerance": 5,
  "equivalent": true
};
Promise.resolve().then(()=>feature(input)).then(value=>{
  console.log(JSON.stringify(value));
}).catch(error=>console.log("ERROR: "+error.message));

Expected:
true
An AI explanation is a hypothesis. Explain the operation, identify missing evidence, propose controlled tests and respect browser/security boundaries. Do not claim to have measured or remotely inspected a site.

Official reference material

MDN Performance API · Google: lab versus field evidence · Browser capability and measurement boundaries

Next full lesson