Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@time can't handle top-level-only expressions #5352

Closed
gitfoxi opened this issue Jan 10, 2014 · 10 comments
Closed

@time can't handle top-level-only expressions #5352

gitfoxi opened this issue Jan 10, 2014 · 10 comments
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)

Comments

@gitfoxi
Copy link
Contributor

gitfoxi commented Jan 10, 2014

I don't really care that this doesn't work.

julia> @time using DataFrames
ERROR: unsupported or misplaced expression using

But it could

julia> @time eval(parse("using DataFrames"))
elapsed time: 5.558196165 seconds (64795540 bytes allocated)

Also, does anyone think the bytes allocated means something?

julia> function fib(n)
        n < 2 && return n
        return fib(n-1) + fib(n-2)
       end
fib (generic function with 1 method)

julia> @time fib(40)
elapsed time: 1.244510557 seconds (33068 bytes allocated)
102334155

julia> @time fib(40)
elapsed time: 1.102346687 seconds (64 bytes allocated)
102334155

Wow. Only 64 bytes allocated that is efficient.

@StefanKarpinski
Copy link
Member

Macro syntax is space sensitive. You can also write @time(using DataFrames).

The bytes allocated means how many bytes were allocated while evaluating the expression, including code generation. Why would fib need to allocate more than the return value?

@JeffBezanson
Copy link
Member

The bytes allocated doesn't distinguish bytes allocated by the user code from bytes allocated during compilation. The 64 bytes in the last case is probably allocation of a couple boxes to shuttle the result to the REPL and such.

using is one of the top-level-only expressions, which does make it hard to handle. In general, a case like this would be quite perverse (you wouldn't time, say, a type definition), but it just so happens that using is very slow and so an important thing to time.

@StefanKarpinski
Copy link
Member

Is there any way we can turn off the gc_bytes incrementing while doing code gen?

@JeffBezanson
Copy link
Member

We probably could, but by the principle of generally preferring transparency the effort might not be worth it. We'd have to go through the code and save the gc counter before every bit we consider off limits, then reset it. You will also get strange results like 0 bytes allocated for code that generates code --- sometimes compilation is logically part of the user program.

@JeffBezanson
Copy link
Member

Of course I don't mean 0 bytes literally, just an artificially low number.

@StefanKarpinski
Copy link
Member

Yeah, it's probably better the way it is. People just need to understand that sometimes running something generates code, which takes up both time and memory. Since we can't avoid the time taken by code generation, it would almost be more confusing to not report the bytes allocated. This way the @time output gives two hints that compilation is occurring vs. not occurring: the amount of time and the number of bytes.

@JeffBezanson
Copy link
Member

Yes, I think that's exactly how Tim and I felt about it when he first added the bytes counter.

@simonster
Copy link
Member

You can @time require("DataFrames"), which seems fine since nearly all of the time it takes to do using DataFrames is in loading the code.

@quinnj
Copy link
Member

quinnj commented Jun 5, 2014

Hmmm....is there something we should do for @time using DataFrames? Maybe throw an error suggesting to do require? The gc issue here is superseded by #7119.

@KristofferC
Copy link
Member

KristofferC commented Jan 22, 2017

This now seems to work:

julia> @time using Tokenize
  0.014877 seconds (26.78 k allocations: 1.450 MB)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage)
Projects
None yet
Development

No branches or pull requests

7 participants