Skip to content

Instantly share code, notes, and snippets.

@VAndrJ
Created March 11, 2024 13:09
Show Gist options
  • Save VAndrJ/c0bdbaebb803fe8db4fb0c7c05ce01ee to your computer and use it in GitHub Desktop.
Save VAndrJ/c0bdbaebb803fe8db4fb0c7c05ce01ee to your computer and use it in GitHub Desktop.
Swift compilation time benchmark
#!/usr/bin/env python3
import os
filenames = ["a", "b"]
codeMixed = [
'someFunc(data: SomeClass(data: SomeStruct(data: SomeStruct.Nested1.Nested2(point: CGPoint(x: {}, y: {})))))',
'someFunc(data: .init(data: .init(data: .init(point: .init(x: {}, y: {})))))'
]
for (i, filename) in enumerate(filenames):
with open(filename + ".swift", "w") as f:
s = """import CoreGraphics
struct SomeStruct { struct Nested1 { struct Nested2 { let point: CGPoint } }; let data: Nested1.Nested2 }
class SomeClass { let data: SomeStruct; init(data: SomeStruct) { self.data = data } }
func someFunc(data: SomeClass) { _ = data.data.data.point }
"""
for j in range(25600):
s += (codeMixed[i] + '\n').format(j, j)
f.write(s)
os.system("hyperfine 'xcrun swiftc -typecheck {}'".format(filename + ".swift"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment