# Elapsed + allocated?

**URL:** https://discourse.julialang.org/t/elapsed-allocated/125910
**Category:** Performance
**Tags:** question
**Created:** [February 14, 2025, 2:30pm UTC](https://discourse.julialang.org/t/elapsed-allocated/125910 "2025-02-14T14:30:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Sarah\_Groves](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sarah_groves/32/207216_2.png) [@Sarah\_Groves](https://discourse.julialang.org/u/Sarah_Groves)
#### Post date: [February 14, 2025, 2:30pm UTC](https://discourse.julialang.org/t/elapsed-allocated/125910/1 "2025-02-14T14:30:37Z")

</div>

I am familiar with the @elapsed and @allocated functions that allow me to save as a variable either the elapsed time and allocated memory during a function run (respectively). Is there a method that will return both variables at once so they can both be saved to variables? Thanks!

---

<div class="post-metadata">

### Author: ![danielwe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielwe/32/35657_2.png) [@danielwe](https://discourse.julialang.org/u/danielwe)
#### Post date: [February 14, 2025, 2:34pm UTC](https://discourse.julialang.org/t/elapsed-allocated/125910/2 "2025-02-14T14:34:46Z")

</div>

Try `@timed`

---

<div class="post-metadata">

### Author: ![Sarah\_Groves](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sarah_groves/32/207216_2.png) [@Sarah\_Groves](https://discourse.julialang.org/u/Sarah_Groves)
#### Post date: [February 14, 2025, 4:26pm UTC](https://discourse.julialang.org/t/elapsed-allocated/125910/3 "2025-02-14T16:26:45Z")

</div>

Thank you! That was so simple but I’m a beginner at Julia and couldn’t find it.

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [February 14, 2025, 4:34pm UTC](https://discourse.julialang.org/t/elapsed-allocated/125910/4 "2025-02-14T16:34:48Z")

</div>

That’s what help forums like this are for sometimes! (Also sometimes for more complex problems) Welcome. 🙂

---

<div class="post-metadata">

### Author: ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)
#### Post date: [February 14, 2025, 5:08pm UTC](https://discourse.julialang.org/t/elapsed-allocated/125910/5 "2025-02-14T17:08:53Z")

</div>

> [@Sarah\_Groves](#):
>
> I’m a beginner at Julia and couldn’t find it.

It’s definitely not a foolproof method, but the _See also_ part of the documentation (type ? in the REPL) is often useful:

```julia-repl
help?> @elapsed
  @elapsed

  A macro to evaluate an expression, discarding the resulting value, instead returning the number of seconds it took
  to execute as a floating-point number.

  In some cases the system will look inside the @elapsed expression and compile some of the called code before
  execution of the top-level expression begins. When that happens, some compilation time will not be counted. To
  include this time you can run @elapsed @eval ....

  See also @time, @timev, @timed, @allocated, and @allocations.

  julia> @elapsed sleep(0.3)
  0.301391426

```

leading you to `@timed`.
