I'm trying to render the Mandelbrot set quickly so I remade the calculations function in web assembly thinking it would be faster but it is the same speed
(module
(func (export "getcolorj") (param f64 f64 f64 f64) (result i32) (local f64 f64 i32 f64 f64)
local.get 0
local.set 4;;cx=x
local.get 1
local.set 5;;ci=i
i32.const 0
local.set 6;;i3=0
(block
(loop
local.get 4
local.get 4
f64.mul
local.get 5
local.get 5
f64.mul
f64.sub
local.set 7;;const temp=cx**2-ci**2
local.get 4
local.get 5
f64.mul
f64.const 2
f64.mul
local.get 3
f64.add
local.set 5;;ci=cx*ci*2+i
local.get 7
local.get 2
f64.add
local.set 4;;cx=temp+x
local.get 4
local.get 4
f64.mul
local.get 5
local.get 5
f64.mul
f64.add
local.set 7;;(cx**2+ci**2)
local.get 6
i32.const 1
i32.add
local.set 6;;i3++
(i32.eq (local.get 6) (i32.const 100))
(f64.gt (local.get 7) (f64.const 4))
i32.add
(i32.ne (i32.const 0))
br_if 1
(br 0)
)
)
local.get 6
i32.const -1
i32.add
)
)
vs
function getcolorj(x,i,juliusx,juliusi,deap){
var cx= x
var ci= i
var i3=0
for("";i3<deap;i3++){
const temp=cx**2-ci**2
ci=cx*ci*2+juliusi
cx=temp+juliusx
if((cx**2+ci**2)>4){break;}
}
return i3
}
I don't know what I did wrong or if this is just how it is, did I just make the web assembly poorly? this is my first time trying it so if it is the case I wouldn't be too surprised
JIC how I started it matters:
WebAssembly.instantiateStreaming(fetch('test.wasm'), {})
.then(results => {
console.log()
getcolorj=results.instance.exports.getcolorj
});
btw I'm doing 10,000 interactions for qualitys sake, and yeah both slow down when rendering the black sections.