Skip to content

Expensive setup

Josh Hiles edited this page Dec 22, 2023 · 1 revision

If an experiment requires expensive setup that should only occur when the experiment is going to be run, define it with the BeforeRun method:

public int DoSomethingExpensive()
{
    return Scientist.Science<int>("expensive-but-worthwile", experiment =>
    {
        experiment.BeforeRun(() => ExpensiveSetup());

        experiment.Use(() => TheOldWay());
        experiment.Try(() => TheNewWay());
    });
}