Module: XmlCompilerBenchmarks
- Defined in:
- lib/tasks/xml_compiler_benchmark.rb
Constant Summary collapse
- SCHEMAS =
Shared test schemas
{ small: " <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n <xs:element name=\"root\" type=\"RootType\"/>\n <xs:complexType name=\"RootType\">\n <xs:sequence>\n <xs:element name=\"child\" type=\"xs:string\" maxOccurs=\"unbounded\"/>\n </xs:sequence>\n <xs:attribute name=\"id\" type=\"xs:string\"/>\n </xs:complexType>\n </xs:schema>\n XSD\n medium: <<~XSD,\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n targetNamespace=\"http://example.com/test\"\n xmlns:tns=\"http://example.com/test\">\n <xs:element name=\"document\" type=\"tns:DocumentType\"/>\n <xs:complexType name=\"DocumentType\">\n <xs:sequence>\n <xs:element name=\"header\" type=\"tns:HeaderType\"/>\n <xs:element name=\"body\" type=\"tns:BodyType\" maxOccurs=\"unbounded\"/>\n </xs:sequence>\n <xs:attribute name=\"version\" type=\"xs:string\"/>\n </xs:complexType>\n <xs:complexType name=\"HeaderType\">\n <xs:sequence>\n <xs:element name=\"title\" type=\"xs:string\"/>\n <xs:element name=\"author\" type=\"tns:PersonType\" maxOccurs=\"unbounded\"/>\n </xs:sequence>\n </xs:complexType>\n <xs:complexType name=\"PersonType\">\n <xs:sequence>\n <xs:element name=\"firstName\" type=\"xs:string\"/>\n <xs:element name=\"lastName\" type=\"xs:string\"/>\n </xs:sequence>\n <xs:attribute name=\"id\" type=\"xs:ID\"/>\n </xs:complexType>\n <xs:complexType name=\"BodyType\">\n <xs:sequence>\n <xs:element name=\"section\" type=\"tns:SectionType\" maxOccurs=\"unbounded\"/>\n </xs:sequence>\n </xs:complexType>\n <xs:complexType name=\"SectionType\">\n <xs:sequence>\n <xs:element name=\"heading\" type=\"xs:string\"/>\n <xs:choice>\n <xs:element name=\"paragraph\" type=\"tns:ParagraphType\"/>\n <xs:element name=\"list\" type=\"tns:ListType\"/>\n </xs:choice>\n </xs:sequence>\n <xs:attribute name=\"id\" type=\"xs:ID\"/>\n </xs:complexType>\n <xs:complexType name=\"ParagraphType\" mixed=\"true\">\n <xs:sequence>\n <xs:element name=\"emphasis\" type=\"xs:string\" minOccurs=\"0\" maxOccurs=\"unbounded\"/>\n </xs:sequence>\n </xs:complexType>\n <xs:complexType name=\"ListType\">\n <xs:sequence>\n <xs:element name=\"item\" type=\"xs:string\" maxOccurs=\"unbounded\"/>\n </xs:sequence>\n </xs:complexType>\n </xs:schema>\n XSD\n}.freeze\n",
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 |