WEBVTT

1
00:00:00.180 --> 00:00:03.802
When does preparation repay its cost?

2
00:00:03.802 --> 00:00:10.223
A reusable representation can take time to build before it answers a query.

3
00:00:10.223 --> 00:00:14.507
We will compare total time for the same queries and the same output,

4
00:00:14.507 --> 00:00:20.787
using an explicitly hypothetical example. You will learn to include the build cost,

5
00:00:20.787 --> 00:00:25.385
locate equality, and distinguish it from the first strict improvement.

6
00:00:25.565 --> 00:00:29.594
Assume direct evaluation takes three milliseconds per query.

7
00:00:29.594 --> 00:00:36.896
The prepared method costs one hundred twenty
milliseconds to build and half a millisecond per query.

8
00:00:36.896 --> 00:00:40.785
Both return the same single Boolean answer for each input.

9
00:00:40.785 --> 00:00:45.522
These numbers illustrate a method; they are not measurements of this repository.

10
00:00:45.702 --> 00:00:51.194
Let N be the number of queries. Direct evaluation costs three N milliseconds.

11
00:00:51.194 --> 00:00:55.013
The prepared path costs one hundred twenty plus half N.

12
00:00:55.013 --> 00:01:01.711
The build cost is paid once only if the prepared artifact can actually be reused across those queries.

13
00:01:01.891 --> 00:01:03.737
Set the two costs equal.

14
00:01:03.737 --> 00:01:09.705
Subtract half N from both sides, giving two and a half N equals one hundred twenty.

15
00:01:09.705 --> 00:01:10.936
Divide to obtain

16
00:01:10.936 --> 00:01:13.803
Divide to obtain forty-eight queries.

17
00:01:13.803 --> 00:01:16.486
At exactly forty-eight, both paths take

18
00:01:16.486 --> 00:01:19.712
At exactly forty-eight, both paths take one hundred forty-four milliseconds under our assumptions.

19
00:01:19.892 --> 00:01:27.230
At ten queries, direct evaluation takes thirty milliseconds,
while preparation plus queries takes one hundred twenty-five.

20
00:01:27.230 --> 00:01:33.139
At one hundred queries, direct takes three hundred and prepared takes one hundred seventy.

21
00:01:33.139 --> 00:01:39.431
The preferable path changes with reuse, even though each prepared query is faster.

22
00:01:39.611 --> 00:01:46.484
A real experiment must say whether parsing, compilation,
caches, conversion, and final output are included.

23
00:01:46.484 --> 00:01:52.719
Use the same inputs, verify results first, and report
repeated measurements with host and software details.

24
00:01:52.719 --> 00:01:56.642
A warm cached run and a cold run answer different questions.

25
00:01:56.822 --> 00:02:00.769
In our hypothetical model, equality occurs at forty-eight queries.

26
00:02:00.769 --> 00:02:05.855
What is the smallest whole number of queries for which the prepared method is strictly faster?

27
00:02:05.855 --> 00:02:21.206
Calculate both totals there rather than rounding the equality point into a claimed win.

28
00:02:21.642 --> 00:02:24.150
At forty-nine queries, the direct total is

29
00:02:24.150 --> 00:02:26.715
At forty-nine queries, the direct total is one hundred forty-seven milliseconds.

30
00:02:26.715 --> 00:02:28.132
The prepared total is

31
00:02:28.132 --> 00:02:30.314
The prepared total is one hundred forty-four and a half.

32
00:02:30.314 --> 00:02:34.807
That is the first whole-query count with a strict improvement in this model.

33
00:02:34.807 --> 00:02:38.510
Different build or query costs would change the crossover.
