# Is \`=\` fast in Clojure?

**URL:** https://clojureverse.org/t/is-fast-in-clojure/2182
**Category:** General Questions
**Created:** [May 25, 2018, 4:03am UTC](https://clojureverse.org/t/is-fast-in-clojure/2182 "2018-05-25T04:03:17Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![jonasseglare](https://clojureverse.org/user_avatar/clojureverse.org/jonasseglare/32/1201_2.png) [@jonasseglare](https://clojureverse.org/u/jonasseglare)
#### Post date: [May 25, 2018, 5:15am UTC](https://clojureverse.org/t/is-fast-in-clojure/2182/2 "2018-05-25T05:15:38Z")

</div>

I would suppose that this depends from case to case how fast = is. Here is some code that tests one particular case:

```
(defn make-deep-data [n]
  (reduce (fn [dst x]
            [x dst])
          nil
          (range n)))

(def depths (take 12 (iterate (partial * 2) 1)))

(doseq [d depths]
  (let [a (make-deep-data d)
        b (make-deep-data d)]
    (println "\nFor depth d" d)
    (time (= a b))
    (println "Comparing to itself")
    (time (= a a))))

```

and print outs this

```
For depth d 1
"Elapsed time: 0.038561 msecs"
Comparing to itself
"Elapsed time: 0.002133 msecs"

For depth d 2
"Elapsed time: 0.003985 msecs"
Comparing to itself
"Elapsed time: 0.001997 msecs"

For depth d 4
"Elapsed time: 0.004792 msecs"
Comparing to itself
"Elapsed time: 0.0012 msecs"

For depth d 8
"Elapsed time: 0.00445 msecs"
Comparing to itself
"Elapsed time: 0.001583 msecs"

For depth d 16
"Elapsed time: 0.009612 msecs"
Comparing to itself
"Elapsed time: 0.002007 msecs"

For depth d 32
"Elapsed time: 0.015544 msecs"
Comparing to itself
"Elapsed time: 0.001894 msecs"

For depth d 64
"Elapsed time: 0.029676 msecs"
Comparing to itself
"Elapsed time: 0.002145 msecs"

For depth d 128
"Elapsed time: 0.057724 msecs"
Comparing to itself
"Elapsed time: 0.001697 msecs"

For depth d 256
"Elapsed time: 0.130804 msecs"
Comparing to itself
"Elapsed time: 0.001664 msecs"

For depth d 512
"Elapsed time: 0.162453 msecs"
Comparing to itself
"Elapsed time: 0.001934 msecs"

For depth d 1024
"Elapsed time: 0.524108 msecs"
Comparing to itself
"Elapsed time: 0.001896 msecs"

For depth d 2048
"Elapsed time: 0.701173 msecs"
Comparing to itself
"Elapsed time: 0.002049 msecs"

```

So if they are identical (same references) there is no extra costs of them being deep. But if they are equal, but with different memory, there seems to be a cost that depends on the size of the data structure _for this particular example_. You can do a similar experiment for your use case and that might give you an idea, but I would suppose that = is just what you want in most cases.

It would be nice if someone could point to an article describing more in-depth how Clojure’s equality mechanism works.

---

_[View the full topic](https://clojureverse.org/t/is-fast-in-clojure/2182)._
