vectorize a zero parameter function.
import { assertLessOrEqual as assertLe, assertGreaterOrEqual as assertGe,} from "jsr:@std/assert"const rand = () => 100 * Math.random()const arr = new Float32Array(10_000)vectorize0(rand, arr) // `arr` is now filled with random numbers ranging from `0.0` to `100.0`const average_of_arr = arr.reduce((cumulative_sum, value) => (cumulative_sum + value), 0) / arr.lengthassertLe(average_of_arr, 60.0)assertGe(average_of_arr, 40.0) Copy
import { assertLessOrEqual as assertLe, assertGreaterOrEqual as assertGe,} from "jsr:@std/assert"const rand = () => 100 * Math.random()const arr = new Float32Array(10_000)vectorize0(rand, arr) // `arr` is now filled with random numbers ranging from `0.0` to `100.0`const average_of_arr = arr.reduce((cumulative_sum, value) => (cumulative_sum + value), 0) / arr.lengthassertLe(average_of_arr, 60.0)assertGe(average_of_arr, 40.0)
despite being a simple operation with no inputs, this still performs 4 times quicker than array.map, probably due to the fact that array.map passes three arguments.
array.map
vectorize a zero parameter function.
Example
despite being a simple operation with no inputs, this still performs 4 times quicker than
array.map
, probably due to the fact thatarray.map
passes three arguments.