MVCoconut / coconut.vdom

Coconut rendering through virtual-dom.
The Unlicense
19 stars 8 forks source link

Benchmark handler speed. #12

Closed back2dos closed 5 years ago

back2dos commented 6 years ago

A simple benchmark on Chrome seems to indicate that setting onclick is faster than addEventListener('click'): https://try.haxe.org/#c3d21

Should properly verify across browser and make the diffing work accordingly.

sh-dave commented 6 years ago

Seems to be 50:50 for me on what runs faster (tested the thing like 30 times on chrome 69.0.3497.92). Times ranging from: 0.36 - 0.45 for both. Similar results for edge 42.17134.1.0, except a lot slower with times ranging from 0.6 - 0.8.

16:44:00:316   Test.hx:10: fill
16:44:00:717   Test.hx:23: 0.40000009536743164s
16:44:00:717   Test.hx:10: fill
16:44:01:166   Test.hx:30: 0.44699978828430176s
16:45:00:219   Test.hx:10: fill
16:45:00:621   Test.hx:23: 0.40000009536743164s
16:45:00:621   Test.hx:10: fill
16:45:01:014   Test.hx:30: 0.3900001049041748s
16:45:25:576   Test.hx:10: fill
16:45:25:989   Test.hx:23: 0.41100001335144043s
16:45:25:990   Test.hx:10: fill
16:45:26:374   Test.hx:30: 0.38300013542175293s
16:49:39:364   Test.hx:10: fill
16:49:39:753   Test.hx:23: 0.38700008392333984s
16:49:39:753   Test.hx:10: fill
16:49:40:158   Test.hx:30: 0.4029998779296875s
back2dos commented 6 years ago

Interesting. For me on Chrome it's slightly faster for onclick, but FF is roughly equal. I have another one, that simulates something slightly closer to what patching does (i.e. replacing handlers): https://try.haxe.org/#AEfB4 ... seems to tend more clearly towards onclick. But well, useful benchmarking is not that easy ...

sh-dave commented 6 years ago

Yes, in the 2nd test onClick seems consistently faster for me as well.

back2dos commented 5 years ago

I'm just going to file this under "fast enough". In any case https://github.com/MVCoconut/coconut.ui/issues/31 should have more significant effects than microoptimizing handlers.