quickjs-ng / quickjs

QuickJS, the Next Generation: a mighty JavaScript engine
MIT License
691 stars 66 forks source link

Add custom printf version (Draft) #390

Open chqrlie opened 2 months ago

chqrlie commented 2 months ago

Add custom printf version

bnoordhuis commented 2 months ago

I'm sorta lukewarm on this. Prior experiences with homegrown (s)printf implementations have been a mixed bag.

I mean, I get the appeal but complex features need to pay for themselves and I'm not quite seeing that. Is there one killer feature in particular that made you start on this?

chqrlie commented 2 months ago

I'm sorta lukewarm on this. Prior experiences with homegrown (s)printf implementations have been a mixed bag.

I mean, I get the appeal but complex features need to pay for themselves and I'm not quite seeing that. Is there one killer feature in particular that made you start on this?

Hi @bnoordhuis

I understand your concerns, I have invested a hefty amount of work into this, both for pleasure (I like to hack printf for breakfast*) and for actual goals in this project:

The implementation in the current PR still uses the library snprintf for floating point values, but I am testing a complete version and will post that shortly. I shall also add a complete test suite with 450000 tests: qjs_printf passes and is on average 50% faster than the C library versions on Apple and linux).

As you have noticed, Fabrice and I tried hard to avoid depending on other packages to keep the project self contained and reliable. printf is a remaining stone is our shoes that I would like to get rid of too.


(*) Implementing printf for breakfast is a good challenge for C experts, getting all the integer conversions right is feasible, but handling the floating point conversions correctly (and efficiently) does require time and effort :)

bnoordhuis commented 1 month ago

@chqrlie I don't have much time this week and (maybe) next week (school holidays) but I'll try to review this at the first possible opportunity.

chqrlie commented 1 month ago

@chqrlie I don't have much time this week and (maybe) next week (school holidays) but I'll try to review this at the first possible opportunity.

Thank you. I have not plugged js_dtoa into this yet, so you may want to wait for a final version... I'll keep you posted.