toon-format 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea09cf3e7e8073107069d8f2551d9ebe50835c35d3215bfdaf9b08dbd90d3593
4
- data.tar.gz: d4d0b25983e5e109fe6fc2e2cdbee40fae8ff2a8349ec1cbaa59a3f4e43f3042
3
+ metadata.gz: bd5e1effad5c2a4d4914013127e02bb0840171384c9ad36866860e07f8c14ccc
4
+ data.tar.gz: a66d07a5d109865efa6a25b267039eb1005b33133a697d500d239138cb3304c9
5
5
  SHA512:
6
- metadata.gz: fac767b126082dd4601d230155fab6c8d03ee0ece251abbcc818352e5439256f2f748c695e449382669584b86e342b688c27cef792947da4eeed4cc1b4b674ad
7
- data.tar.gz: 86152667c32998de7324f44b1d6db8de12bbb90468038cff74ed5dcc6b2e7d54a0fc1ea876ac7e17023bbc02e160e7e6d0441fb09a7efd2d32705816fba56bd7
6
+ metadata.gz: 14f333af3d0c876f04f101555444f5f5353a37977f17336625d9748b530b64089cf933a5f52090807bd4c633ed3c7554b46b1dac46991e72f975346767df4ca9
7
+ data.tar.gz: f718201f24e07b828872c882c90a3b1b9352d9b9a9676d6d489673b4f6703ee919a9e862e367f390f5d7069c2ec53ad02fad7cca23f78e4a251acebebdc208df
@@ -19,7 +19,7 @@ end
19
19
 
20
20
  puts "=" * 80
21
21
  puts "Format Comparison Benchmark"
22
- puts "Comparing TOON with JSON, YAML#{MSGPACK_AVAILABLE ? ', and MessagePack' : ''}"
22
+ puts "Comparing TOON with JSON, YAML#{", and MessagePack" if MSGPACK_AVAILABLE}"
23
23
  puts "=" * 80
24
24
  puts
25
25
 
@@ -155,7 +155,5 @@ puts "When to use each format:"
155
155
  puts " • JSON: Universal compatibility, well-established"
156
156
  puts " • YAML: Configuration files, human editing priority"
157
157
  puts " • TOON: LLM contexts, API responses, token optimization"
158
- if MSGPACK_AVAILABLE
159
- puts " • MessagePack: Maximum compression, binary protocols"
160
- end
158
+ puts " • MessagePack: Maximum compression, binary protocols" if MSGPACK_AVAILABLE
161
159
  puts "=" * 80
@@ -24,18 +24,18 @@ puts
24
24
 
25
25
  # Test data sets with varying sizes
26
26
  data_sets = {
27
- "Small (10 records)" => Array.new(10) { |i|
27
+ "Small (10 records)" => Array.new(10) do |i|
28
28
  { id: i, name: "User#{i}", email: "user#{i}@example.com", active: i.even? }
29
- },
30
- "Medium (100 records)" => Array.new(100) { |i|
29
+ end,
30
+ "Medium (100 records)" => Array.new(100) do |i|
31
31
  { id: i, name: "User#{i}", email: "user#{i}@example.com", active: i.even? }
32
- },
33
- "Large (1,000 records)" => Array.new(1000) { |i|
32
+ end,
33
+ "Large (1,000 records)" => Array.new(1000) do |i|
34
34
  { id: i, name: "User#{i}", email: "user#{i}@example.com", active: i.even? }
35
- },
36
- "Very Large (10,000 records)" => Array.new(10_000) { |i|
35
+ end,
36
+ "Very Large (10,000 records)" => Array.new(10_000) do |i|
37
37
  { id: i, name: "User#{i}", email: "user#{i}@example.com", active: i.even? }
38
- }
38
+ end
39
39
  }
40
40
 
41
41
  data_sets.each do |name, data|
@@ -56,9 +56,9 @@ data_sets.each do |name, data|
56
56
  puts "TOON encoding (1000 iterations): #{toon_memory} KB"
57
57
 
58
58
  diff = json_memory - toon_memory
59
- if diff > 0
59
+ if diff.positive?
60
60
  puts "Memory saved: #{diff} KB (#{((diff / json_memory.to_f) * 100).round(1)}%)"
61
- elsif diff < 0
61
+ elsif diff.negative?
62
62
  puts "Memory overhead: #{diff.abs} KB (#{((diff.abs / json_memory.to_f) * 100).round(1)}%)"
63
63
  else
64
64
  puts "Memory usage: equivalent"
@@ -81,9 +81,9 @@ data_sets.each do |name, data|
81
81
  puts "TOON decoding (1000 iterations): #{toon_decode_memory} KB"
82
82
 
83
83
  diff = json_decode_memory - toon_decode_memory
84
- if diff > 0
84
+ if diff.positive?
85
85
  puts "Memory saved: #{diff} KB (#{((diff / json_decode_memory.to_f) * 100).round(1)}%)"
86
- elsif diff < 0
86
+ elsif diff.negative?
87
87
  puts "Memory overhead: #{diff.abs} KB (#{((diff.abs / json_decode_memory.to_f) * 100).round(1)}%)"
88
88
  else
89
89
  puts "Memory usage: equivalent"
@@ -57,7 +57,7 @@ depths.each do |depth|
57
57
  puts "Nesting Depth: #{depth}"
58
58
  puts "-" * 80
59
59
  puts "JSON size: #{json_str.bytesize} bytes"
60
- puts "TOON size: #{toon_str.bytesize} bytes (#{((1 - toon_str.bytesize.to_f / json_str.bytesize) * 100).round(1)}% difference)"
60
+ puts "TOON size: #{toon_str.bytesize} bytes (#{((1 - (toon_str.bytesize.to_f / json_str.bytesize)) * 100).round(1)}% difference)"
61
61
  puts
62
62
 
63
63
  Benchmark.ips do |x|
@@ -118,9 +118,9 @@ puts "=" * 80
118
118
  puts
119
119
 
120
120
  wide_structure = {
121
- data: Array.new(100) { |i|
121
+ data: Array.new(100) do |i|
122
122
  { id: i, name: "Item#{i}", value: rand(100) }
123
- }
123
+ end
124
124
  }
125
125
 
126
126
  deep_structure = create_nested_object(15)
@@ -130,7 +130,7 @@ puts "-" * 80
130
130
  json_wide = JSON.generate(wide_structure)
131
131
  toon_wide = ToonFormat.encode(wide_structure)
132
132
  puts "JSON: #{json_wide.bytesize} bytes"
133
- puts "TOON: #{toon_wide.bytesize} bytes (#{((1 - toon_wide.bytesize.to_f / json_wide.bytesize) * 100).round(1)}% difference)"
133
+ puts "TOON: #{toon_wide.bytesize} bytes (#{((1 - (toon_wide.bytesize.to_f / json_wide.bytesize)) * 100).round(1)}% difference)"
134
134
  puts
135
135
 
136
136
  Benchmark.ips do |x|
@@ -166,21 +166,21 @@ puts "=" * 80
166
166
  puts
167
167
 
168
168
  complex_data = {
169
- users: Array.new(20) { |i|
169
+ users: Array.new(20) do |i|
170
170
  {
171
171
  id: i,
172
172
  name: "User#{i}",
173
- posts: Array.new(5) { |j|
173
+ posts: Array.new(5) do |j|
174
174
  {
175
175
  id: j,
176
176
  title: "Post #{j}",
177
- comments: Array.new(3) { |k|
177
+ comments: Array.new(3) do |k|
178
178
  { id: k, text: "Comment #{k}", likes: rand(10) }
179
- }
179
+ end
180
180
  }
181
- }
181
+ end
182
182
  }
183
- }
183
+ end
184
184
  }
185
185
 
186
186
  json_complex = JSON.generate(complex_data)
@@ -190,7 +190,7 @@ puts "20 users × 5 posts × 3 comments = 300 total items"
190
190
  puts "-" * 80
191
191
  puts "JSON size: #{json_complex.bytesize} bytes"
192
192
  puts "TOON size: #{toon_complex.bytesize} bytes"
193
- puts "Savings: #{((1 - toon_complex.bytesize.to_f / json_complex.bytesize) * 100).round(1)}%"
193
+ puts "Savings: #{((1 - (toon_complex.bytesize.to_f / json_complex.bytesize)) * 100).round(1)}%"
194
194
  puts
195
195
 
196
196
  Benchmark.ips do |x|
@@ -38,7 +38,7 @@ toon_response = ToonFormat.encode(api_users)
38
38
  puts "Response sizes:"
39
39
  puts " JSON: #{json_response.bytesize} bytes (~#{(json_response.bytesize / 4.0).ceil} tokens)"
40
40
  puts " TOON: #{toon_response.bytesize} bytes (~#{(toon_response.bytesize / 4.0).ceil} tokens)"
41
- puts " Savings: #{((1 - toon_response.bytesize.to_f / json_response.bytesize) * 100).round(1)}%"
41
+ puts " Savings: #{((1 - (toon_response.bytesize.to_f / json_response.bytesize)) * 100).round(1)}%"
42
42
  puts
43
43
 
44
44
  Benchmark.ips do |x|
@@ -57,7 +57,7 @@ puts
57
57
 
58
58
  products = Array.new(200) do |i|
59
59
  {
60
- sku: "PROD#{i.to_s.rjust(5, '0')}",
60
+ sku: "PROD#{i.to_s.rjust(5, "0")}",
61
61
  name: "Product #{i}",
62
62
  category: %w[Electronics Clothing Books Home].sample,
63
63
  price: (rand(10..1000) * 100) / 100.0,
@@ -74,7 +74,7 @@ toon_export = ToonFormat.encode(products)
74
74
  puts "Export sizes:"
75
75
  puts " JSON: #{json_export.bytesize} bytes"
76
76
  puts " TOON: #{toon_export.bytesize} bytes"
77
- puts " Savings: #{((1 - toon_export.bytesize.to_f / json_export.bytesize) * 100).round(1)}%"
77
+ puts " Savings: #{((1 - (toon_export.bytesize.to_f / json_export.bytesize)) * 100).round(1)}%"
78
78
  puts
79
79
 
80
80
  Benchmark.ips do |x|
@@ -96,7 +96,7 @@ chat_history = Array.new(20) do |i|
96
96
  id: i + 1,
97
97
  role: i.even? ? "user" : "assistant",
98
98
  content: "This is message number #{i + 1} in the conversation. " * 3,
99
- timestamp: "2025-01-26T#{(10 + i).to_s.rjust(2, '0')}:30:00Z",
99
+ timestamp: "2025-01-26T#{(10 + i).to_s.rjust(2, "0")}:30:00Z",
100
100
  tokens: rand(50..200)
101
101
  }
102
102
  end
@@ -145,7 +145,7 @@ toon_events = ToonFormat.encode(analytics_events)
145
145
  puts "Event log sizes:"
146
146
  puts " JSON: #{json_events.bytesize} bytes"
147
147
  puts " TOON: #{toon_events.bytesize} bytes"
148
- puts " Savings: #{((1 - toon_events.bytesize.to_f / json_events.bytesize) * 100).round(1)}%"
148
+ puts " Savings: #{((1 - (toon_events.bytesize.to_f / json_events.bytesize)) * 100).round(1)}%"
149
149
  puts " Bandwidth saved per 1000 requests: #{((json_events.bytesize - toon_events.bytesize) * 1000 / 1024.0).round(2)} KB"
150
150
  puts
151
151
 
@@ -201,7 +201,7 @@ toon_config = ToonFormat.encode(config)
201
201
  puts "Config sizes:"
202
202
  puts " JSON (pretty): #{json_config.bytesize} bytes"
203
203
  puts " TOON: #{toon_config.bytesize} bytes"
204
- puts " Savings: #{((1 - toon_config.bytesize.to_f / json_config.bytesize) * 100).round(1)}%"
204
+ puts " Savings: #{((1 - (toon_config.bytesize.to_f / json_config.bytesize)) * 100).round(1)}%"
205
205
  puts
206
206
 
207
207
  Benchmark.ips do |x|
@@ -21,29 +21,29 @@ datasets = {
21
21
  active: true
22
22
  },
23
23
 
24
- "Small Array (10 records)" => Array.new(10) { |i|
24
+ "Small Array (10 records)" => Array.new(10) do |i|
25
25
  { id: i, name: "User#{i}", email: "user#{i}@example.com" }
26
- },
26
+ end,
27
27
 
28
- "Medium Array (100 records)" => Array.new(100) { |i|
28
+ "Medium Array (100 records)" => Array.new(100) do |i|
29
29
  { id: i, name: "User#{i}", email: "user#{i}@example.com", score: rand(100) }
30
- },
30
+ end,
31
31
 
32
- "Large Array (1000 records)" => Array.new(1000) { |i|
32
+ "Large Array (1000 records)" => Array.new(1000) do |i|
33
33
  { id: i, name: "User#{i}", score: rand(100) }
34
- },
34
+ end,
35
35
 
36
36
  "Complex Nested" => {
37
- users: Array.new(20) { |i|
37
+ users: Array.new(20) do |i|
38
38
  {
39
39
  id: i,
40
40
  name: "User#{i}",
41
41
  profile: {
42
42
  age: 20 + i,
43
- tags: ["tag1", "tag2"]
43
+ tags: %w[tag1 tag2]
44
44
  }
45
45
  }
46
- },
46
+ end,
47
47
  metadata: { total: 20, page: 1 }
48
48
  }
49
49
  }
@@ -94,7 +94,7 @@ test_cases = [
94
94
  score: 95.5,
95
95
  active: true,
96
96
  metadata: nil,
97
- tags: ["a", "b"],
97
+ tags: %w[a b],
98
98
  nested: { key: "value" }
99
99
  }]
100
100
  ]
@@ -102,7 +102,7 @@ test_cases = [
102
102
  test_cases.each do |name, data|
103
103
  # JSON round-trip
104
104
  json_encoded = JSON.generate(data)
105
- json_decoded = JSON.parse(json_encoded, symbolize_names: true)
105
+ JSON.parse(json_encoded, symbolize_names: true)
106
106
 
107
107
  # TOON round-trip
108
108
  toon_encoded = ToonFormat.encode(data)
@@ -126,16 +126,16 @@ puts
126
126
 
127
127
  # Test data for multiple round-trips
128
128
  test_data = {
129
- users: Array.new(50) { |i|
129
+ users: Array.new(50) do |i|
130
130
  { id: i, name: "User#{i}", score: rand(100), active: i.even? }
131
- }
131
+ end
132
132
  }
133
133
 
134
134
  puts "Testing 10 consecutive round-trips..."
135
135
  puts "-" * 80
136
136
 
137
137
  current = test_data
138
- 10.times do |i|
138
+ 10.times do |_i|
139
139
  encoded = ToonFormat.encode(current)
140
140
  current = ToonFormat.decode(encoded)
141
141
  end
@@ -154,9 +154,9 @@ puts "PERFORMANCE: Multiple Encode-Decode Cycles"
154
154
  puts "=" * 80
155
155
  puts
156
156
 
157
- data = Array.new(100) { |i|
157
+ data = Array.new(100) do |i|
158
158
  { id: i, name: "User#{i}", email: "user#{i}@example.com" }
159
- }
159
+ end
160
160
 
161
161
  puts "100 records, 5 round-trips each iteration:"
162
162
  puts "-" * 80
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require "English"
4
5
  require "fileutils"
5
6
  require "time"
6
7
 
@@ -58,7 +59,7 @@ benchmarks.each_with_index do |(file, description), index|
58
59
  begin
59
60
  # Run the benchmark
60
61
  system("ruby #{benchmark_path}")
61
- status = $?.success? ? "✓ SUCCESS" : "✗ FAILED"
62
+ status = $CHILD_STATUS.success? ? "✓ SUCCESS" : "✗ FAILED"
62
63
  elapsed = Time.now - start_time
63
64
 
64
65
  results << {
@@ -97,7 +98,7 @@ failed = results.count { |r| r[:status] != "✓ SUCCESS" }
97
98
 
98
99
  summary = []
99
100
  summary << "TOON Format Benchmark Suite Results"
100
- summary << "=" * 80
101
+ summary << ("=" * 80)
101
102
  summary << "Run Date: #{Time.now}"
102
103
  summary << "Total Time: #{total_time.round(2)}s"
103
104
  summary << "Total Benchmarks: #{results.size}"
@@ -105,7 +106,7 @@ summary << "Successful: #{successful}"
105
106
  summary << "Failed: #{failed}"
106
107
  summary << ""
107
108
  summary << "Individual Results:"
108
- summary << "-" * 80
109
+ summary << ("-" * 80)
109
110
 
110
111
  results.each_with_index do |result, index|
111
112
  line = "#{index + 1}. #{result[:description]}"
@@ -113,13 +114,11 @@ results.each_with_index do |result, index|
113
114
  line += "#{result[:status]} (#{result[:elapsed].round(2)}s)"
114
115
  summary << line
115
116
 
116
- if result[:error]
117
- summary << " Error: #{result[:error]}"
118
- end
117
+ summary << " Error: #{result[:error]}" if result[:error]
119
118
  end
120
119
 
121
120
  summary << ""
122
- summary << "=" * 80
121
+ summary << ("=" * 80)
123
122
 
124
123
  # Print summary
125
124
  summary.each { |line| puts line }
@@ -64,7 +64,7 @@ sizes.each do |size|
64
64
 
65
65
  puts "\nDataset: #{size} records"
66
66
  puts " JSON size: #{json_str.bytesize} bytes"
67
- puts " TOON size: #{toon_str.bytesize} bytes (#{((1 - toon_str.bytesize.to_f / json_str.bytesize) * 100).round(1)}% smaller)"
67
+ puts " TOON size: #{toon_str.bytesize} bytes (#{((1 - (toon_str.bytesize.to_f / json_str.bytesize)) * 100).round(1)}% smaller)"
68
68
  puts "-" * 80
69
69
 
70
70
  Benchmark.ips do |x|
@@ -103,7 +103,7 @@ results = {}
103
103
 
104
104
  json_str = JSON.generate(data)
105
105
  toon_str = ToonFormat.encode(data)
106
- size_reduction = ((1 - toon_str.bytesize.to_f / json_str.bytesize) * 100).round(1)
106
+ size_reduction = ((1 - (toon_str.bytesize.to_f / json_str.bytesize)) * 100).round(1)
107
107
 
108
108
  results[size] = {
109
109
  speedup: speedup,
@@ -14,27 +14,27 @@ puts
14
14
 
15
15
  # Test datasets
16
16
  datasets = {
17
- "Small (10 records)" => Array.new(10) { |i|
17
+ "Small (10 records)" => Array.new(10) do |i|
18
18
  { id: i, name: "User#{i}", email: "user#{i}@example.com", active: i.even? }
19
- },
19
+ end,
20
20
 
21
- "Medium (100 records)" => Array.new(100) { |i|
21
+ "Medium (100 records)" => Array.new(100) do |i|
22
22
  { id: i, name: "User#{i}", email: "user#{i}@example.com", active: i.even? }
23
- },
23
+ end,
24
24
 
25
- "Large (1000 records)" => Array.new(1000) { |i|
25
+ "Large (1000 records)" => Array.new(1000) do |i|
26
26
  { id: i, name: "User#{i}", email: "user#{i}@example.com", active: i.even? }
27
- },
27
+ end,
28
28
 
29
29
  "Nested Structure" => {
30
- users: Array.new(50) { |i|
30
+ users: Array.new(50) do |i|
31
31
  {
32
32
  id: i,
33
33
  name: "User#{i}",
34
34
  age: 20 + i,
35
35
  city: "City#{i % 10}"
36
36
  }
37
- },
37
+ end,
38
38
  metadata: {
39
39
  total: 50,
40
40
  page: 1,
@@ -70,7 +70,7 @@ datasets.each do |name, data|
70
70
  end
71
71
 
72
72
  # Test validation overhead with different complexities
73
- puts "\n" + "=" * 80
73
+ puts "\n#{"=" * 80}"
74
74
  puts "Validation Overhead Analysis"
75
75
  puts "=" * 80
76
76
  puts
@@ -83,9 +83,9 @@ puts "Dataset Size | Strict (ms) | Lenient (ms) | Overhead (%)"
83
83
  puts "-" * 80
84
84
 
85
85
  test_sizes.each do |size|
86
- data = Array.new(size) { |i|
86
+ data = Array.new(size) do |i|
87
87
  { id: i, name: "User#{i}", email: "user#{i}@example.com", score: rand(100) }
88
- }
88
+ end
89
89
 
90
90
  toon_str = ToonFormat.encode(data)
91
91
 
@@ -8,8 +8,8 @@ module ToonFormat
8
8
  #
9
9
  # @param options [Hash] Encoding options
10
10
  # @return [String] TOON formatted string
11
- def to_toon(**options)
12
- ToonFormat.encode(as_json, **options)
11
+ def to_toon(**)
12
+ ToonFormat.encode(as_json, **)
13
13
  end
14
14
  end
15
15
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ToonFormat
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toon-format
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Osman Okuyan
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2025-11-27 00:00:00.000000000 Z
11
12
  dependencies: []
12
13
  description: Compact serialization format optimized for LLM contexts with 30-60% token
13
14
  reduction compared to JSON
@@ -54,8 +55,9 @@ licenses:
54
55
  - MIT
55
56
  metadata:
56
57
  homepage_uri: https://github.com/osmanok/toon-format
57
- source_code_uri: https://github.com/osmanokuyan/toon-format
58
- changelog_uri: https://github.com/osmanokuyan/toon-format/blob/main/CHANGELOG.md
58
+ source_code_uri: https://github.com/osmanok/toon-format
59
+ changelog_uri: https://github.com/osmanok/toon-format/blob/main/CHANGELOG.md
60
+ post_install_message:
59
61
  rdoc_options: []
60
62
  require_paths:
61
63
  - lib
@@ -63,14 +65,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
65
  requirements:
64
66
  - - ">="
65
67
  - !ruby/object:Gem::Version
66
- version: 3.0.0
68
+ version: 3.2.0
67
69
  required_rubygems_version: !ruby/object:Gem::Requirement
68
70
  requirements:
69
71
  - - ">="
70
72
  - !ruby/object:Gem::Version
71
73
  version: '0'
72
74
  requirements: []
73
- rubygems_version: 3.7.2
75
+ rubygems_version: 3.4.19
76
+ signing_key:
74
77
  specification_version: 4
75
78
  summary: TOON format serialization for Ruby
76
79
  test_files: []