Module: Lutaml::Model::Performance::TestModels
- Defined in:
- lib/tasks/performance_benchmark.rb
Overview
Shared test models for benchmarks
Defined Under Namespace
Classes: Address, Order, OrderItem, Person, SimpleModel
Class Method Summary collapse
- .order_instance(id: 0) ⇒ Object
- .order_xml(count: 1) ⇒ Object
- .person_instance(id: 0) ⇒ Object
- .person_xml(count: 1) ⇒ Object
- .simple_model_instance(id: 0) ⇒ Object
- .simple_model_xml(count: 1) ⇒ Object
Class Method Details
.order_instance(id: 0) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/tasks/performance_benchmark.rb', line 232 def order_instance(id: 0) items = Array.new(5) do |j| OrderItem.new( product_id: (id * 10) + j, quantity: j + 1, price: (j + 1) * 9.99, ) end Order.new( id: id, customer: Person.new( id: id * 100, first_name: "Customer", last_name: id.to_s, email: "customer#{id}@example.com", age: 30, address: Address.new( street: "#{id} Order St", city: "OrderCity", zip: "20000", country: "OrderLand", ), ), items: items, total: (id + 1) * 49.95, status: "pending", ) end |
.order_xml(count: 1) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/tasks/performance_benchmark.rb', line 170 def order_xml(count: 1) orders = Array.new(count) do |i| items_xml = Array.new(5) do |j| <<~XML <item product_id="#{(i * 10) + j}"> <quantity>#{j + 1}</quantity> <price>#{(j + 1) * 9.99}</price> </item> XML end.join <<~XML <order id="#{i}"> <customer id="#{i * 100}"> <first_name>Customer</first_name> <last_name>#{i}</last_name> <email>customer#{i}@example.com</email> <age>30</age> <address> <street>#{i} Order St</street> <city>OrderCity</city> <zip>20000</zip> <country>OrderLand</country> </address> </customer> #{items_xml} <total>#{(i + 1) * 49.95}</total> <status>pending</status> </order> XML end orders.join("\n") end |
.person_instance(id: 0) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/tasks/performance_benchmark.rb', line 214 def person_instance(id: 0) Person.new( id: id, first_name: "John#{id}", last_name: "Doe#{id}", email: "john#{id}@example.com", age: 25 + (id % 50), address: Address.new( street: "#{id} Main St", city: "City#{id}", zip: (10000 + id).to_s, country: "Country#{id % 10}", ), phone_numbers: ["555-#{1000 + id}", "555-#{2000 + id}"], tags: ["tag#{id % 5}", "tag#{(id + 1) % 5}"], ) end |
.person_xml(count: 1) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/tasks/performance_benchmark.rb', line 146 def person_xml(count: 1) people = Array.new(count) do |i| <<~XML <person id="#{i}"> <first_name>John#{i}</first_name> <last_name>Doe#{i}</last_name> <email>john#{i}@example.com</email> <age>#{25 + (i % 50)}</age> <address> <street>#{i} Main St</street> <city>City#{i}</city> <zip>#{10000 + i}</zip> <country>Country#{i % 10}</country> </address> <phone_number>555-#{1000 + i}</phone_number> <phone_number>555-#{2000 + i}</phone_number> <tag>tag#{i % 5}</tag> <tag>tag#{(i + 1) % 5}</tag> </person> XML end people.join("\n") end |
.simple_model_instance(id: 0) ⇒ Object
204 205 206 207 208 209 210 211 212 |
# File 'lib/tasks/performance_benchmark.rb', line 204 def simple_model_instance(id: 0) SimpleModel.new( id: id, name: "Test Name #{id}", active: true, score: id + 0.5, created_at: Time.new(2024, 1, (id % 28) + 1, 10, 0, 0), ) end |
.simple_model_xml(count: 1) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/tasks/performance_benchmark.rb', line 132 def simple_model_xml(count: 1) items = Array.new(count) do |i| <<~XML <simple id="#{i}"> <name>Test Name #{i}</name> <active>true</active> <score>#{i}.5</score> <created_at>2024-01-#{(i % 28) + 1}T10:00:00Z</created_at> </simple> XML end items.join("\n") end |