Yes! I should have mentioned that earlier. You can use `eval("js", script);`

from the macro language to invoke JavaScript snippets.

Here is an example macro that does some per-pixel math normally:

## Per_Pixel_Math.ijm

```
newImage("Untitled", "8-bit noise", 4000, 4001, 1);
start = getTime();
print("Calculating pixels...");
for (y=0; y<getHeight(); y++) {
for (x=0; x<getWidth(); x++) {
value = 128 * (cos(x / 20.0) + sin(y / 20.0) + 1);
setPixel(x, y, value);
}
}
end = getTime();
print("Calculation took " + ((end - start) / 1000.0) + " seconds")
```

On my system, it runs in 21.2 seconds, or ~1.32 microseconds per pixel.

And here is the same example, but with the per-pixel loop wrapped in JavaScript using `eval`

:

## Per_Pixel_Math_Optimized_with_JS.ijm

```
newImage("Untitled", "8-bit noise", 4000, 4001, 1);
start = getTime();
print("Calculating pixels...");
script = "" +
"importClass(Packages.ij.IJ)\n" +
"importClass(Packages.java.lang.Math)\n" +
"imp = IJ.getImage();\n" +
"ip = imp.getProcessor();\n" +
"for (y=0; y<ip.getHeight(); y++) {\n" +
" for (x=0; x<ip.getWidth(); x++) {\n" +
" value = 128 * (Math.cos(x / 20.0) + Math.sin(y / 20.0) + 1);\n" +
" ip.setf(x, y, value);\n" +
" }\n" +
"}\n" +
"imp.updateAndDraw();\n";
eval("js", script);
end = getTime();
print("Calculation took " + ((end - start) / 1000.0) + " seconds")
```

On my system, this version runs in 3.2 seconds, or ~0.2 microseconds per pixel, more than 6x faster than pure IJM.