# Why is the destroy benchmark Activerecord/sqlite3 destroy bench creating

**URL:** <https://community.rubybench.org/t/why-is-the-destroy-benchmark-activerecord-sqlite3-destroy-bench-creating/61>\
**Category:** Uncategorized\
**Created:** [April 16, 2015, 11:35pm UTC](https://community.rubybench.org/t/why-is-the-destroy-benchmark-activerecord-sqlite3-destroy-bench-creating/61 "2015-04-16T23:35:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam](https://sea2.discourse-cdn.com/flex016/user_avatar/community.rubybench.org/sam/32/5_2.png) [@sam](https://community.rubybench.org/u/sam)\
**Post date:** [April 16, 2015, 11:35pm UTC](https://community.rubybench.org/t/why-is-the-destroy-benchmark-activerecord-sqlite3-destroy-bench-creating/61/1 "2015-04-16T23:35:34Z")

</div>

```auto
Benchmark.rails("activerecord/sqlite3_destroy", time: 10) do
   user = User.create!(attributes)
   user.destroy
 end

```

This looks really weird to me. Why is the destroy benchmark creating, its not benchmarking the correct operation.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/rubybench/original/1X/4ae23b7eff9a1b039e126f05dd734ab09c8ab4b5.png) [@system](https://community.rubybench.org/u/system)\
**Post date:** [April 17, 2015, 12:32am UTC](https://community.rubybench.org/t/why-is-the-destroy-benchmark-activerecord-sqlite3-destroy-bench-creating/61/2 "2015-04-17T00:32:47Z")

</div>

I created the user within the benchmark because on the first iteration, the user would have already been destroyed from the database and the second `destroy` does not end up hitting the DB…I might be wrong ☹

---

<div class="post-metadata">

**Author:** ![sam](https://sea2.discourse-cdn.com/flex016/user_avatar/community.rubybench.org/sam/32/5_2.png) [@sam](https://community.rubybench.org/u/sam)\
**Post date:** [April 17, 2015, 12:48am UTC](https://community.rubybench.org/t/why-is-the-destroy-benchmark-activerecord-sqlite3-destroy-bench-creating/61/3 "2015-04-17T00:48:47Z")

</div>

Either:

```auto
user = nil
Benchmark.rails("activerecord/sqlite3_destroy", before: lambda {
 user = User.create!(attributes)
}) do
    user.destroy
 end

```

Or:

```auto
iterations = 10000

users = [0..(iterations + warmup)].map{ User.create!(attributes)}

Benchmark.rails("activerecord/sqlite3_destroy", iterations: iterations) do
    users.first.destroy
end

```

---

<div class="post-metadata">

**Author:** ![shatrov](https://sea2.discourse-cdn.com/flex016/user_avatar/community.rubybench.org/shatrov/32/42_2.png) [@shatrov](https://community.rubybench.org/u/shatrov)\
**Post date:** [April 21, 2015, 10:04pm UTC](https://community.rubybench.org/t/why-is-the-destroy-benchmark-activerecord-sqlite3-destroy-bench-creating/61/4 "2015-04-21T22:04:35Z")

</div>

Great suggestion, I’ll improve the helper in this way.
