# "Maps directly to actual computer hardware" - how would I know?

**URL:** <https://forums.kodeco.com/t/maps-directly-to-actual-computer-hardware-how-would-i-know/140511>\
**Category:** Expert Swift\
**Created:** [May 20, 2021, 11:11am UTC](https://forums.kodeco.com/t/maps-directly-to-actual-computer-hardware-how-would-i-know/140511 "2021-05-20T11:11:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lganti](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/lganti/32/103565_2.png) [@lganti](https://forums.kodeco.com/u/lganti)\
**Post date:** [May 20, 2021, 11:11am UTC](https://forums.kodeco.com/t/maps-directly-to-actual-computer-hardware-how-would-i-know/140511/1 "2021-05-20T11:11:14Z")

</div>

```auto
example("imperative, early-exit") {
  var total = 0
  for value in numbers {
    guard value >= 0 else { break }
    total += value
  }
  print(total)
}

```

> “It also maps directly to actual computer hardware so the optimizer doesn’t have to work nearly as hard.”

Along what lines should I be thinking to come to this conclusion? What are the keywords I should be looking up to be able to draw these sort of conclusions?

---

<div class="post-metadata">

**Author:** ![freak4pc](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/freak4pc/32/101113_2.png) [@freak4pc](https://forums.kodeco.com/u/freak4pc)\
**Post date:** [May 22, 2021, 5:00am UTC](https://forums.kodeco.com/t/maps-directly-to-actual-computer-hardware-how-would-i-know/140511/2 "2021-05-22T05:00:41Z")

</div>

Can you take a look @rayfix ?

---

<div class="post-metadata">

**Author:** ![rayfix](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rayfix/32/108995_2.png) [@rayfix](https://forums.kodeco.com/u/rayfix)\
**Post date:** [May 22, 2021, 5:53am UTC](https://forums.kodeco.com/t/maps-directly-to-actual-computer-hardware-how-would-i-know/140511/3 "2021-05-22T05:53:05Z")

</div>

Thanks for the question. What I mean to express here is that because the solution is imperative and CPUs are also by their very nature, imperative state machines, the mapping (or lowering) to machine instructions is very direct.

In this very particular case, LLVM is so smart that I wouldn’t be surprised if it unrolled the loop and found the answer at compile time so that at runtime, it would just print a literal number.

Compiler lowering and optimization is a very deep subject and one could earn many PHDs exploring the space!

I don’t know if that answers your question but let me know if you would like more clarification.

---

<div class="post-metadata">

**Author:** ![rayfix](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rayfix/32/108995_2.png) [@rayfix](https://forums.kodeco.com/u/rayfix)\
**Post date:** [May 22, 2021, 6:24am UTC](https://forums.kodeco.com/t/maps-directly-to-actual-computer-hardware-how-would-i-know/140511/4 "2021-05-22T06:24:17Z")

</div>

One more thought… choosing the clearest programming style is many times the best way to go. Only worry about the performance after you have solved the problem correctly. 🙂

---

<div class="post-metadata">

**Author:** ![lganti](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/lganti/32/103565_2.png) [@lganti](https://forums.kodeco.com/u/lganti)\
**Post date:** [May 22, 2021, 1:35pm UTC](https://forums.kodeco.com/t/maps-directly-to-actual-computer-hardware-how-would-i-know/140511/5 "2021-05-22T13:35:25Z")

</div>

Thanks Ray and Shai!
