From a047ed8f8e804e4934ebcf889c053cf631a34d95 Mon Sep 17 00:00:00 2001 From: brice Date: Mon, 7 Dec 2020 20:37:03 +0000 Subject: [PATCH] performance test --- README.md | 8 +++++-- .../FitFileParserSwiftTests.swift | 23 +++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 8e7f4fe..67eda31 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/Tests/FitFileParserSwiftTests/FitFileParserSwiftTests.swift b/Tests/FitFileParserSwiftTests/FitFileParserSwiftTests.swift index 99136e7..8502757 100644 --- a/Tests/FitFileParserSwiftTests/FitFileParserSwiftTests.swift +++ b/Tests/FitFileParserSwiftTests/FitFileParserSwiftTests.swift @@ -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), ] }