diff options
| author | Mike Pall <mike> | 2022-06-23 09:10:43 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2022-06-23 09:10:43 +0200 |
| commit | 4c2441c16ce3c4e312aaefecc6d40c4fe21de97c (patch) | |
| tree | 0ee5ad7a3246f9a620265de9c6998308cb44a09b /doc/ext_ffi.html | |
| parent | 0065cff7e0222c234b75a71e72b8883df5d000c2 (diff) | |
| parent | 2e98c3d0644fc0c265844908f43b7e4526dd819c (diff) | |
| download | luajit-4c2441c16ce3c4e312aaefecc6d40c4fe21de97c.tar.gz luajit-4c2441c16ce3c4e312aaefecc6d40c4fe21de97c.tar.bz2 luajit-4c2441c16ce3c4e312aaefecc6d40c4fe21de97c.zip | |
Merge branch 'master' into v2.1
Diffstat (limited to 'doc/ext_ffi.html')
| -rw-r--r-- | doc/ext_ffi.html | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/doc/ext_ffi.html b/doc/ext_ffi.html index 85104ba5..b39ae314 100644 --- a/doc/ext_ffi.html +++ b/doc/ext_ffi.html | |||
| @@ -157,7 +157,7 @@ call the binding function. Phew! | |||
| 157 | <h2 id="cdata">Motivating Example: Using C Data Structures</h2> | 157 | <h2 id="cdata">Motivating Example: Using C Data Structures</h2> |
| 158 | <p> | 158 | <p> |
| 159 | The FFI library allows you to create and access C data | 159 | The FFI library allows you to create and access C data |
| 160 | structures. Of course the main use for this is for interfacing with | 160 | structures. Of course, the main use for this is for interfacing with |
| 161 | C functions. But they can be used stand-alone, too. | 161 | C functions. But they can be used stand-alone, too. |
| 162 | </p> | 162 | </p> |
| 163 | <p> | 163 | <p> |
| @@ -169,7 +169,7 @@ implemented with a big table holding lots of tiny tables. This imposes | |||
| 169 | both a substantial memory overhead as well as a performance overhead. | 169 | both a substantial memory overhead as well as a performance overhead. |
| 170 | </p> | 170 | </p> |
| 171 | <p> | 171 | <p> |
| 172 | Here's a sketch of a library that operates on color images plus a | 172 | Here's a sketch of a library that operates on color images, plus a |
| 173 | simple benchmark. First, the plain Lua version: | 173 | simple benchmark. First, the plain Lua version: |
| 174 | </p> | 174 | </p> |
| 175 | <pre class="code"> | 175 | <pre class="code"> |
| @@ -184,7 +184,7 @@ local function image_ramp_green(n) | |||
| 184 | return img | 184 | return img |
| 185 | end | 185 | end |
| 186 | 186 | ||
| 187 | local function image_to_grey(img, n) | 187 | local function image_to_gray(img, n) |
| 188 | for i=1,n do | 188 | for i=1,n do |
| 189 | local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue) | 189 | local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue) |
| 190 | img[i].red = y; img[i].green = y; img[i].blue = y | 190 | img[i].red = y; img[i].green = y; img[i].blue = y |
| @@ -194,14 +194,14 @@ end | |||
| 194 | local N = 400*400 | 194 | local N = 400*400 |
| 195 | local img = image_ramp_green(N) | 195 | local img = image_ramp_green(N) |
| 196 | for i=1,1000 do | 196 | for i=1,1000 do |
| 197 | image_to_grey(img, N) | 197 | image_to_gray(img, N) |
| 198 | end | 198 | end |
| 199 | </pre> | 199 | </pre> |
| 200 | <p> | 200 | <p> |
| 201 | This creates a table with 160.000 pixels, each of which is a table | 201 | This creates a table with 160.000 pixels, each of which is a table |
| 202 | holding four number values in the range of 0-255. First an image with | 202 | holding four number values in the range of 0-255. First, an image with |
| 203 | a green ramp is created (1D for simplicity), then the image is | 203 | a green ramp is created (1D for simplicity), then the image is |
| 204 | converted to greyscale 1000 times. Yes, that's silly, but I was in | 204 | converted to grayscale 1000 times. Yes, that's silly, but I was in |
| 205 | need of a simple example ... | 205 | need of a simple example ... |
| 206 | </p> | 206 | </p> |
| 207 | <p> | 207 | <p> |
| @@ -308,7 +308,7 @@ be more compact and faster. This is certainly true (by a factor of | |||
| 308 | ~1.7x). Switching to a struct-of-arrays would help, too. | 308 | ~1.7x). Switching to a struct-of-arrays would help, too. |
| 309 | </p> | 309 | </p> |
| 310 | <p style="font-size: 8pt;"> | 310 | <p style="font-size: 8pt;"> |
| 311 | However the resulting code would be less idiomatic and rather | 311 | However, the resulting code would be less idiomatic and rather |
| 312 | error-prone. And it still doesn't get even close to the performance of | 312 | error-prone. And it still doesn't get even close to the performance of |
| 313 | the FFI version of the code. Also, high-level data structures cannot | 313 | the FFI version of the code. Also, high-level data structures cannot |
| 314 | be easily passed to other C functions, especially I/O functions, | 314 | be easily passed to other C functions, especially I/O functions, |
