Skip to content

alternative to do block: start_timing! and stop_timing! #197

@zot

Description

@zot

Chunk 2 fails if I enclose chunk 1 in a do block.

@timeit "chunk 1" begin
	local var1 = func1()
	local var2 = func2()
	local var3 = func3()
end
@timeit "chunk 2" begin
	compute_with(var1, var2, var3)
end
with_timer("chunk 3") do
   ... lots of other code that uses var1, var2, and var3
end

It'd be nice if I could sometimes time things without a do block:

# code chunk 1
local timer = start_timing!(t, "chunk 1")
local var1 = func1()
local var2 = func2()
local var3 = func3()
stop_timing!(timer)

@timeit "chunk 2" begin
	compute_with(var1, var2, var3)
end
with_timer("chunk 3") do
   ... lots of other code that uses var1, var2, and var3
end

You could do it like below but separate timers are nicer because otherwise you have to restructure your code simply because you are timing it and large numbers of variables make it even more awkward...

local var1, var2, var3 = with_timer("chunk1") do
   func1(), func2(), func3()
end

For throws, if start_timing! happens to be within an outer with_timer block and there's a throw before the stop_timing! call occurs, the outer timing block can clean up the mess.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions