Using debug_show vs. type specific toText method?

I’m assuming there’s a performance difference between using debug_show and toText type of APIs when formatting values as text within a Motoko canister, but has anyone benchmarked this to see just how much less efficient this is?

For example:

  • Nats - Nat.toText(n) vs. debug_show(n)
  • Errors - Error.message(e) vs. debug_show(e)
  • Collections like Buffer - Buffer.toText(b) vs. debug_show(b)

If it’s close, debug_show is just so much more convenient to use.

I take pride in being a lazy developer by letting CoPilot write my code for me :sunglasses: :desert_island:

CoPilot definitely knows how to read my mind, completing my code with debug_show everywhere, but it consistently fumbles in using the right toText APIs for other types/collections.

1 Like