Skip to content

fix: use compact in compare method to showcase token savings benefits (v2.x)#5

Merged
iamgerwin merged 1 commit intomainfrom
fix/compare-compact-method
Jan 25, 2026
Merged

fix: use compact in compare method to showcase token savings benefits (v2.x)#5
iamgerwin merged 1 commit intomainfrom
fix/compare-compact-method

Conversation

@iamgerwin
Copy link
Owner

Summary

  • Changed compare method to use compact() instead of encode()
  • Removed $options parameter since compare should always showcase best-case savings
  • Ensures TOON's token efficiency is properly demonstrated when using the compare method

Rationale

The compare method is designed to showcase the benefits of using TOON over JSON by comparing token usage. Previously, it accepted an optional $options parameter and used encode(), which meant the comparison could use any format (compact, readable, or tabular).

This change:

  • Always uses the compact format, which provides the best token savings
  • Simplifies the API by removing the confusing $options parameter
  • Ensures a consistent, optimal showcase of TOON's token efficiency

Changes

Modified

  • src/Toon.php - Updated compare() method:
    • Removed ?EncodeOptions $options = null parameter
    • Changed $toon = self::encode($value, $options) to $toon = self::compact($value)
    • Updated docblock to clarify that compact format is used

Testing

Run the examples in compact_benefits.php to verify that token savings are properly showcased.

```bash
php compact_benefits.php
```

Branch

This PR targets the main branch (v2.x), which supports PHP 8.1+.

- Changed compare method to use compact() instead of encode()
- Removed off on off off off off off off off off on off on off off off off off on off off off on on off off off off on off off off off off off off off off off off off on off off off off off off off on off on on off off off on off off on off off on off off on off on off off on off on off off off off on off off off on off off on off off off off off off off off on off on off off on off off off off off off off off off off off off on off off off on off on off on on off off off off on on on off on on off on off on on off off off off on on off off on off off off off off on off off on off off on off off off off off off on off off off off on on off on off off off off off on off on off off off off off off off off off off on on off on off off off parameter since compare should always showcase best-case savings
- Ensures TOON's token efficiency is properly demonstrated
@iamgerwin iamgerwin merged commit 20c7d21 into main Jan 25, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant