# Benchmarking / profiling cache use

**URL:** https://discourse.julialang.org/t/benchmarking-profiling-cache-use/7260
**Category:** General Usage
**Tags:** question, performance
**Created:** [November 23, 2017, 1:06am UTC](https://discourse.julialang.org/t/benchmarking-profiling-cache-use/7260 "2017-11-23T01:06:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)
#### Post date: [November 23, 2017, 1:06am UTC](https://discourse.julialang.org/t/benchmarking-profiling-cache-use/7260/1 "2017-11-23T01:06:06Z")

</div>

Hi,  
I wanted to profile cache misses on some code of mine. I appear to be incapable of eyeballing the hardware prefetcher, and wanted to see whether some explicit prefetches improve my code. These are kinda accessible via something like:

```julia
 #this is for read-data that is needed soon.
 #maybe experiment with different locality values?
 #prefetch on instruction cache crashes julia during compilation. meh, not needed anyway.
@inline function prefetch(address)
   Base.llvmcall(("declare void @llvm.prefetch(i8* , i32 , i32 , i32 )",
 "call void @llvm.prefetch(i8 * %0, i32 0, i32 0, i32 1)
 ret void"), Void, Tuple{Ptr{Int8}}, convert(Ptr{Int8},address)) 
end

```

So, how do you people measure e.g. L1 misses in julia code?

Should I try static-julia and (linux-) perf?

If this is indeed the only reasonable way, should I then write my sample code with a @Base.ccallable ju\_main() function, compile into shared library and write a tiny piece of C code that calls the library’s ju\_main? Can I use static-julia to build with debug symbols?

PS. My code does a graph traversal; links are offsets into a fixed array. This is should be very bad for the cache. But I need proper tests before I should consider fancy memory layouts; and a couple explicit prefetches are a much lower effort fix than cache-oblivious stuff.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [November 23, 2017, 9:02am UTC](https://discourse.julialang.org/t/benchmarking-profiling-cache-use/7260/2 "2017-11-23T09:02:05Z")

</div>

Perhaps [GitHub - carnaval/LinuxPerf.jl](https://github.com/carnaval/LinuxPerf.jl) could be of use.

---

<div class="post-metadata">

### Author: ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)
#### Post date: [November 23, 2017, 12:17pm UTC](https://discourse.julialang.org/t/benchmarking-profiling-cache-use/7260/3 "2017-11-23T12:17:11Z")

</div>

Thank you! Google completely failed me there.

This tool is absolutely fantastic; just kindly asking the kernel is obviously much better than a rube-goldberg construction to pass compiled julia into command line tools.

At some point there should be a sticky post / wiki describing these tricks. Carnaval’s IACA.jl also looks extremely interesting.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [November 23, 2017, 12:23pm UTC](https://discourse.julialang.org/t/benchmarking-profiling-cache-use/7260/4 "2017-11-23T12:23:40Z")

</div>

I think this is a continued version of Carnavals IACA: [https://github.com/vchuravy/IACA.jl](https://github.com/vchuravy/IACA.jl)

---

<div class="post-metadata">

### Author: ![system](https://global.discourse-cdn.com/julialang/original/3X/1/2/12829a7ba92b924d4ce81099cbf99785bee9b405.png) [@system](https://discourse.julialang.org/u/system)
#### Post date: [November 24, 2017, 12:23pm UTC](https://discourse.julialang.org/t/benchmarking-profiling-cache-use/7260/5 "2017-11-24T12:23:54Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
