Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Just a typo i guess, If
const square = (x) => { return x * x }
const callFunction100Times = (func) => {
for(let i = 0; i < 100; i++) {
// the func param will be called 100 times
func(2)
}
}
callFunction100Times(square)
was optimized into
const square = (x) => { return x * x }
const callFunction100Times = (func) => {
for(let i = 100; i < 100; i++) {
// the function is inlined so we don't have
// to keep calling func
return x * x
}
}
callFunction100Times(square)
it should lead to serious problems since the return keyword will stop the outer for loop at the first iteration… and this is not what we expected from the source code.
So I think some of these points, especially the ones to do with function inlining might be off now that it’s 2022. I did the following test and found that the later two with side effects were faster, but I’ll have to try some other methods such as changing them to objects to really see what can go wrong
const square = (x) => { return x * x }
const cube = (x) => { return x * x * x }
const obj = { x: 4, y: 3 }
const circle = (x) => { obj.x *= x; return obj.x; };
const circle2 = (x, yObj) => { yObj.x *= x; return yObj.x }
const callFunction100Times = (func) => {
for(let i = 100; i < 100; i++) {
// the function is inlined so we don't have
// to keep calling func
func(2, obj)
}
}
console.time('t')
callFunction100Times(square)
console.timeEnd('t')
console.time('t2')
callFunction100Times(cube)
console.timeEnd('t2')
console.time('t3')
callFunction100Times(circle)
console.timeEnd('t3')
console.time('t4')
callFunction100Times(circle2)
console.timeEnd('t4')