Currently developing futuristic smart-device, IoT connected, highway construction site safety system in EU.
Used to work on infrastructure, application architecture and cloud engineering.
class Program
{
static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<BenchmarkNormalVsCurry>();
}
}
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
[RPlotExporter]
public class BenchmarkNormalVsCurry
{
public static int NormalAdd(int a, int b, int c, int d)
{
return a + b + c + d;
}
public static Func<int, Func<int, Func<int, int>>> CurryAdd(int a) =>
(b) =>
(c) =>
(d) => a + b + c + d;
[Benchmark]
public void TestNormalAdd() => NormalAdd(1, 2, 3, 4);
[Benchmark]
public void TestCurryAdd() => CurryAdd(1)(2)(3)(4);
}
Fantastic that you emphasize this. While FP code constructs unclutter the code, without proper tool support you just move the clutter into the runtime.
Indeed, JavaScript (nor C#) was never designed to go full throttle on functional programming concepts. Therefor the JIT compiler doesn't optimize any of it.
Languages like Haskell, F#, Erlang, Lisp, are built for this, and will handle it in a better way.
I'm definitely interested to know what happens behind all the functions and about compilation. However, I'm not quite experienced at it, but hopefully this will be helpful to others and even me in future.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Normal function in IL:
Curry function in IL:
Benchmark:
the program:
Fantastic that you emphasize this. While FP code constructs unclutter the code, without proper tool support you just move the clutter into the runtime.
Indeed, JavaScript (nor C#) was never designed to go full throttle on functional programming concepts. Therefor the JIT compiler doesn't optimize any of it.
Languages like Haskell, F#, Erlang, Lisp, are built for this, and will handle it in a better way.
Thanks man, for putting this out here!
I'm definitely interested to know what happens behind all the functions and about compilation. However, I'm not quite experienced at it, but hopefully this will be helpful to others and even me in future.