# Cycle burn right?

**URL:** <https://forum.dfinity.org/t/cycle-burn-right/10345>\
**Category:** Developers\
**Tags:** Functional-Programming\
**Created:** [January 18, 2022, 12:55pm UTC](https://forum.dfinity.org/t/cycle-burn-right/10345 "2022-01-18T12:55:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![goose](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/goose/32/6164_2.png) [@goose](https://forum.dfinity.org/u/goose)\
**Post date:** [January 18, 2022, 12:55pm UTC](https://forum.dfinity.org/t/cycle-burn-right/10345/1 "2022-01-18T12:55:12Z")

</div>

The arrayEles contains 1500 elements  
The Orders contains 1700 elements

The following codes consume 6245108 cycles at a time，right?  
The main code for cycle consumption is orders.get(id),why does HashMap consume so many cycles

var orders : HashMap.HashMap\<Text,Info\> = HashMap.fromIter\<Text,Info\>(init.vals(),0, Text.equal, Text.hash);

```
        for ( (id) in arrayEles.vals()){
          
            switch(orders.get(id)){
                case(?v){
                    switch(v.side){
                        case(#1){ ; };
                        case(#2){ ; };
                    };
                };
                case(_){}
            };
        };
```

---

<div class="post-metadata">

**Author:** ![skilesare](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/skilesare/32/5609_2.png) [@skilesare](https://forum.dfinity.org/u/skilesare)\
**Post date:** [January 18, 2022, 8:25pm UTC](https://forum.dfinity.org/t/cycle-burn-right/10345/2 "2022-01-18T20:25:06Z")

</div>

If you want some insight into what is going on you can look at these base libraries. A lot of recursions are going on.

> <https://github.com/dfinity/motoko-base/blob/9947712f044ff5d535b0390389bd63992668875c/src/HashMap.mo#L65>

> <https://github.com/dfinity/motoko-base/blob/9947712f044ff5d535b0390389bd63992668875c/src/AssocList.mo#L14>

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [January 19, 2022, 7:25am UTC](https://forum.dfinity.org/t/cycle-burn-right/10345/3 "2022-01-19T07:25:44Z")

</div>

Maybe your ids are hashing to the same key? `get` doesn’t really do anything heavy—unless it has to traverse through a big `AssocList` within a bucket.

---

<div class="post-metadata">

**Author:** ![goose](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/goose/32/6164_2.png) [@goose](https://forum.dfinity.org/u/goose)\
**Post date:** [January 19, 2022, 9:23am UTC](https://forum.dfinity.org/t/cycle-burn-right/10345/4 "2022-01-19T09:23:14Z")

</div>

Using the Rust implementation, the consumed cycle is one of the 3.5 branches consumed by MOTOKO
