ascii85_test.go 731 B

123456789101112131415161718192021222324252627282930313233343536
  1. package encoding
  2. import (
  3. "encoding/ascii85"
  4. "testing"
  5. "github.com/langgenius/dify-plugin-daemon/tests"
  6. )
  7. func BenchmarkAscii85(b *testing.B) {
  8. var data = []byte("hello world")
  9. var dst = make([]byte, ascii85.MaxEncodedLen(len(data)))
  10. bytes := 0
  11. b.Run("Encode", func(b *testing.B) {
  12. for i := 0; i < b.N; i++ {
  13. ascii85.Encode(dst, data)
  14. bytes += len(data)
  15. }
  16. })
  17. b.Log("Bytes encoded:", tests.ReadableBytes(bytes))
  18. encoded := make([]byte, ascii85.MaxEncodedLen(len(data)))
  19. bytes = 0
  20. ascii85.Encode(encoded, data)
  21. b.Run("Decode", func(b *testing.B) {
  22. for i := 0; i < b.N; i++ {
  23. ascii85.Decode(dst, encoded, true)
  24. bytes += len(encoded)
  25. }
  26. })
  27. b.Log("Bytes decoded:", tests.ReadableBytes(bytes))
  28. }