Skip to content

Commit

Permalink
performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
roznet committed Dec 7, 2020
1 parent fce9734 commit a047ed8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ When a new SDK is available, after download, use the `diffsdk.py` utility that w

You need to then run the `fitconv.py` script that will automatically update the swift code for the latest version of the sdk

## Why implement this Library?

## Why?
The main purpose of this library was speed of parsing the fit file for the ConnectStats use case. It is not the most elegant or the most flexible.

This goal of this code is to replace the original cpp code from the SDK used in FitFileExplorer. The cpp parsing ended up very slow, and it made fit file parsing on [ConnectStats or FitFileExplorer](https://github.com/roznet/connecstats) quite slow. This approach in c/swift is much faster.
This library was built to replace the original cpp code from the SDK used in ConnectStats and FitFileExplorer. As ConnectStats now [receives the FIT files](https://github.com/roznet/connectstats_server) from Garmin, the files are parsed live on the phone as they are received and performance was therefore important for the user experience.

The cpp parsing ended up very slow, and it made fit file parsing on [ConnectStats or FitFileExplorer](https://github.com/roznet/connecstats) quite slow. This approach in c/swift is much faster.

You can check the [benchmarking of the library](https://github.com/roznet/fit-benchmarks) versus a few others.
23 changes: 11 additions & 12 deletions Tests/FitFileParserSwiftTests/FitFileParserSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ final class FitFileParserSwiftTests: XCTestCase {
return resourceURL

}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.

func testParsingPerformance(){
let path = self.findResource(name: "running.fit")
if let data = try? Data(contentsOf: path) {
let fit = FitFile(data: data)
XCTAssertNotNil(fit)
let records = fit.messages(forMessageType: FIT_MESG_NUM_SESSION)
XCTAssertGreaterThan(records.count, 0)
XCTAssertEqual(records.count, fit.countByMessageType()[FIT_MESG_NUM_SESSION])
XCTAssertTrue(fit.hasMessageType(messageType: FIT_MESG_NUM_SESSION))
measure {
let fit = FitFile(data: data)
XCTAssertTrue(fit.hasMessageType(messageType: FIT_MESG_NUM_SESSION))

let records = fit.messages(forMessageType: FIT_MESG_NUM_SESSION)
let countRecords = fit.countByMessageType()[FIT_MESG_NUM_SESSION]
XCTAssertEqual(records.count, countRecords)
}
}
}

static var allTests = [
("testExample", testExample),
("testParsingPerformance", testParsingPerformance),
]
}

0 comments on commit a047ed8

Please sign in to comment.