• Subject: Re: Benchmark: pairs vs. ipairs
• From: "Cheng, Long" <long.x.cheng@...>
• Date: Mon, 30 Nov 2009 10:19:45 +0800

```Again, Yes. "next" is not optimized yet in LJ2.

```
```Hi, list!

```
I'm back again with another silly benchmark (thus, sorry for HTML formatting).
```
```
Now I'm finding the fastest way to calculate sum of values in array part of the table (ignoring hole issues).
```
Source: http://tinyurl.com/yh6mvc3

lua
-------------------------------------------------------------------
name | rel | abs s / iter = us (1e-6 s) / iter
-------------------------------------------------------------------
unrolled | 1.0000 | 45.37 / 10000000 = 4.537000 us
numeric_for | 1.2771 | 57.94 / 10000000 = 5.794000 us
numeric_while | 1.6244 | 73.70 / 10000000 = 7.370000 us
pairs | 3.2927 | 149.39 / 10000000 = 14.939000 us
ipairs | 3.6846 | 167.17 / 10000000 = 16.717000 us
next | 4.3198 | 195.99 / 10000000 = 19.599000 us
luajit2
-------------------------------------------------------------------
name | rel | abs s / iter = us (1e-6 s) / iter
-------------------------------------------------------------------
unrolled | nan | 0.00 / 10000000 = 0.000000 us
numeric_for | inf | 1.90 / 10000000 = 0.190000 us
ipairs | inf | 4.37 / 10000000 = 0.437000 us
numeric_while | inf | 4.43 / 10000000 = 0.443000 us
pairs | inf | 35.79 / 10000000 = 3.579000 us
next | inf | 45.99 / 10000000 = 4.599000 us

```
I'm surprised that (as my colleague pointed out to me), in plain Lua, /pairs/ is *faster* than /ipairs/.
```
```
Also, in unpatched LuaJIT2 b2, /pairs/ is *much* *slower* than /ipairs/ and numeric for... I guess this is another one of beta issues (or I've screwed the benchmark somewhere), but reporting it just in case anyway.
```
Alexander.

P.S. To reproduce, clone

```