# Why Abstract Type is slow?

**URL:** <https://discourse.julialang.org/t/why-abstract-type-is-slow/5146>\
**Category:** General Usage\
**Created:** [July 31, 2017, 4:15am UTC](https://discourse.julialang.org/t/why-abstract-type-is-slow/5146 "2017-07-31T04:15:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![usefulhyun](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/usefulhyun/32/1770_2.png) [@usefulhyun](https://discourse.julialang.org/u/usefulhyun)\
**Post date:** [July 31, 2017, 4:15am UTC](https://discourse.julialang.org/t/why-abstract-type-is-slow/5146/1 "2017-07-31T04:15:33Z")

</div>

Can anyone answer about this question?  
Why use of Integer type makes program slower.  
If you run the below code, you might see it takes about 0.13 second to use the data of type UnitRange{Integer}.

```julia
repetition = 30
mat = rand(1000,1000)
unitrange_integer = UnitRange{Integer}(1:250)
unitrange = UnitRange(1:250)

times_unitrange_integer = Vector{Float64}()
for i=1:repetition
	push!(times_unitrange_integer, @elapsed mat[unitrange_integer, unitrange_integer])
end

times_unitrange = Vector{Float64}()
for i=1:repetition
	push!(times_unitrange, @elapsed mat[unitrange,unitrange])
end

times_hardcoding = Vector{Float64}()
for i=1:repetition
	push!(times_hardcoding, @elapsed mat[1:250,1:250])
end

println(median(times_unitrange_integer),"\t", median(times_unitrange), "\t", median(times_hardcoding))

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [July 31, 2017, 4:26am UTC](https://discourse.julialang.org/t/why-abstract-type-is-slow/5146/2 "2017-07-31T04:26:14Z")

</div>

I thought the comment in the issue you post is already clear enough. If not please first read [the doc](https://docs.julialang.org/en/latest/manual/performance-tips/#Avoid-fields-with-abstract-type-1).
