Last active
August 17, 2024 14:30
-
-
Save kojix2/bf758a30ded3ea9aff9d3151df6a59c1 to your computer and use it in GitHub Desktop.
Investigate crystal compile time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr | |
index 38880ee9e..c51e2c7ef 100644 | |
--- a/src/compiler/crystal/compiler.cr | |
+++ b/src/compiler/crystal/compiler.cr | |
@@ -204,15 +204,28 @@ module Crystal | |
# Raises `InvalidByteSequenceError` if the source code is not | |
# valid UTF-8. | |
def compile(source : Source | Array(Source), output_filename : String) : Result | |
+ t1 = Time.monotonic | |
source = [source] unless source.is_a?(Array) | |
+ t1 = Time.monotonic | |
program = new_program(source) | |
+ t2 = Time.monotonic | |
+ puts " - new_program: #{t2 - t1}" | |
node = parse program, source | |
+ t3 = Time.monotonic | |
+ puts " - parse: #{t3 - t2}" | |
node = program.semantic node, cleanup: !no_cleanup? | |
+ t4 = Time.monotonic | |
+ puts " - semantic: #{t4 - t3}" | |
units = codegen program, node, source, output_filename unless @no_codegen | |
+ t5 = Time.monotonic | |
+ puts " - codegen: #{t5 - t4}" | |
@progress_tracker.clear | |
print_macro_run_stats(program) | |
print_codegen_stats(units) | |
+ t6 = Time.monotonic | |
+ puts " - cleanup: #{t6 - t5}" | |
+ puts " - total: #{t6 - t1}" | |
Result.new program, node | |
end | |
diff --git a/src/llvm.cr b/src/llvm.cr | |
index 84c9dc89a..e49086c68 100644 | |
--- a/src/llvm.cr | |
+++ b/src/llvm.cr | |
@@ -149,7 +149,10 @@ module LLVM | |
{% unless LibLLVM::IS_LT_130 %} | |
def self.run_passes(module mod : Module, passes : String, target_machine : TargetMachine, options : PassBuilderOptions) | |
+ t0 = Time.monotonic | |
LibLLVM.run_passes(mod, passes, target_machine, options) | |
+ t1 = Time.monotonic | |
+ puts " - LibLLVM.run_passes #{t1 - t0}" | |
end | |
{% end %} | |
diff --git a/src/llvm/target_machine.cr b/src/llvm/target_machine.cr | |
index b9de8296d..8457063ae 100644 | |
--- a/src/llvm/target_machine.cr | |
+++ b/src/llvm/target_machine.cr | |
@@ -38,7 +38,10 @@ class LLVM::TargetMachine | |
end | |
private def emit_to_file(llvm_mod, filename, type) | |
+ t0 = Time.monotonic | |
status = LibLLVM.target_machine_emit_to_file(self, llvm_mod, filename, type, out error_msg) | |
+ t1 = Time.monotonic | |
+ puts " - LibLLVM.target_machine_emit_to_file #{t1 - t0}" | |
unless status == 0 | |
raise LLVM.string_and_dispose(error_msg) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment