Module: XmlCompilerBenchmarks
- Defined in:
- lib/tasks/xml_compiler_benchmark.rb
Constant Summary collapse
- SCHEMAS =
Shared test schemas
{ small: <<~XSD, medium: <<~XSD, }.freeze
Class Method Summary collapse
- .benchmark_code_generation ⇒ Object
- .benchmark_module_handling ⇒ Object
- .benchmark_string_operations ⇒ Object
- .run_all ⇒ Object
Class Method Details
.benchmark_code_generation ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/tasks/xml_compiler_benchmark.rb', line 92 def benchmark_code_generation puts "-" * 40 puts "Code Generation Benchmark" puts "-" * 40 job = Benchmark::IPS::Job.new job.config(time: 5, warmup: 2) job.report("to_models(small)") do Lutaml::Model::Schema::XmlCompiler.to_models( SCHEMAS[:small], load_classes: false, create_files: false, module_namespace: "Small", ) end job.report("to_models(medium)") do Lutaml::Model::Schema::XmlCompiler.to_models( SCHEMAS[:medium], load_classes: false, create_files: false, module_namespace: "Medium", ) end job.run puts end |
.benchmark_module_handling ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/tasks/xml_compiler_benchmark.rb', line 148 def benchmark_module_handling puts "-" * 40 puts "Module Namespace Handling Benchmark" puts "-" * 40 job = Benchmark::IPS::Job.new job.config(time: 3, warmup: 1) deep_namespace = "Foo::Bar::Baz::Qux" job.report("split each time") do deep_namespace.split("::") end # Simulated cached version cached = deep_namespace.split("::") job.report("cached modules") do cached.map { |m| m } end job.run puts end |
.benchmark_string_operations ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/tasks/xml_compiler_benchmark.rb', line 122 def benchmark_string_operations puts "-" * 40 puts "String Operations Benchmark" puts "-" * 40 job = Benchmark::IPS::Job.new job.config(time: 3, warmup: 1) job.report("Utils.camel_case") do Lutaml::Model::Utils.camel_case("test_string") Lutaml::Model::Utils.camel_case("another_test") end job.report("Utils.snake_case") do Lutaml::Model::Utils.snake_case("TestString") Lutaml::Model::Utils.snake_case("AnotherTest") end job.report("split(':') + last") do "foo:Bar:Baz".split(":").last end job.run puts end |
.run_all ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tasks/xml_compiler_benchmark.rb', line 81 def run_all puts "=" * 80 puts "XML Compiler Performance Benchmarks" puts "=" * 80 puts benchmark_code_generation benchmark_string_operations benchmark_module_handling end |