Performance Testing of Swift Projects

SPM supports Testing, but afaik only “correctness” testing. That is, testing in the Test Driven Development sense.

But is there a way to run performance testing? I’d like to build a library with different sorting algorithms, to learn more about them, and I was thinking how awesome it’d be to be able to test their performance for small and big inputs. But I don’t think SPM provides something like that?

Anyway. I think it would also help in general to test the asymptotic performance of e.g. the Stdlib, parsers and compute engines.

And if there isn’t a SPM-way of doing it, how’d you recommend I do it?

1 Like

XCTestCase has a measure method (documentation, implementation).

I haven’t used it outside of Xcode, so I don’t know if you can set the “baseline” measurement.

1 Like

Wow! That is really cool :slight_smile:

I’d still like to be able to pass parametrized (e.g. by size) input, but maybe I can do that in the test suite itself somehow :thinking:

The baseline point you mention is crucial, though. I’m gonna investigate how it’d work outside of XCode.

i’ve wondered this for a long time. I wish Swift had a way of annotating a for loop such that the compiler would never try to optimize around it

1 Like

Ohhh. That would allow for :thinking: the creation of performance testing libraries, wouldn’t it? Because even though the compiler might be able to optimize a “dummy for” that’s actually a benchmark, you wouldn’t want it to do so in this case.

Or am I missing something? I might bc I’m very tired :thinking:

If that’s what we’re missing maybe we should make a pitch

das exactly what i’m proposing lol

1 Like

(Ohh, I’m glad my brain’s still kinda working then xD)

Let’s brainstorm this!
Or would you rather just pitch it right away? If you have a good idea of the hows and whys then :+1:t2:

(See ya tomorrow, atm I’m… gonna go sleep :sleeping:)

i have like 3 proposals i have to get around to writing before this one (character integer literals → namespace keyword → contiguous tuples) but ya i’d love to. the syntax i’d like to use would probably be something like @optimize(none) which would also be nice because it would let you specify maximum optimization in debug and Onone builds: @optimize(3)