Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I obtained slightly different results on NestedBareInit and NestedExplicitInit #2

Open
saeed-rz opened this issue Dec 31, 2023 · 2 comments

Comments

@saeed-rz
Copy link

How did I test it:

  • I used swiftc -typecheck {file} command.
  • I removed import Foundation ( it was not necessary)
  • I copied base to my test file, ( to avoid any other effects on compile time)
    Here is NestedBareInit after changes:
struct Base {
    let nested1: Nested1
    let nested2: Nested2
}

struct Nested1 {
    let grand1: GrandChild
    let grand2: GrandChild
}

struct Nested2 {
    let grand: GrandChild
}

struct GrandChild { }

let a0: Base = .init(nested1: .init(grand1: .init(), grand2: .init()), nested2: .init(grand: .init()))
....
let a999: Base = .init(nested1: .init(grand1: .init(), grand2: .init()), nested2: .init(grand: .init()))

NestedExplicitInit.swift:

struct Base {
    let nested1: Nested1
    let nested2: Nested2
}

struct Nested1 {
    let grand1: GrandChild
    let grand2: GrandChild
}

struct Nested2 {
    let grand: GrandChild
}

struct GrandChild { }

let b0 = Base(nested1: Nested1(grand1: GrandChild(), grand2: GrandChild()), nested2: Nested2(grand: GrandChild()))
...
let b999 = Base(nested1: Nested1(grand1: GrandChild(), grand2: GrandChild()), nested2: Nested2(grand: GrandChild()))

Command to test:

hyperfine 'swiftc -typecheck {NestedBareInit/NestedExplicitInit}.swift'

Results:
NestedBareInit:

Time (mean ± σ):     534.0 ms ±  15.6 ms    [User: 483.7 ms, System: 37.7 ms]
  Range (min … max):   518.4 ms … 565.7 ms    10 runs

NestedExplicitInit:

Time (mean ± σ):      1.594 s ±  0.023 s    [User: 1.550 s, System: 0.029 s]
  Range (min … max):    1.568 s …  1.644 s    10 runs
@saeed-rz saeed-rz changed the title I obtained slightly different results. I obtained slightly different results on NestedBareInit and NestedExplicitInit Dec 31, 2023
@LucasVanDongen
Copy link
Owner

What kind of machine/specs did you use?

I'm a bit surprised that you get significantly less ms on NestedBareInit, but NestedExplicitInit takes the double, while all optimizations have been applied on both tests

@saeed-rz
Copy link
Author

saeed-rz commented Jan 1, 2024

I'm using M1 Max 64 GB. Mac os Sonoma 14.1.1 and Xcode Version 15.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants