-
Notifications
You must be signed in to change notification settings - Fork 0
Improve parser library performance and documentation #124
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
parser/src/test/kotlin/dev/hossain/timeline/ParserPerformanceTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package dev.hossain.timeline | ||
|
|
||
| import com.google.common.truth.Truth.assertThat | ||
| import kotlin.test.Test | ||
| import kotlin.time.measureTime | ||
|
|
||
| /** | ||
| * Performance test for [Parser] to validate efficiency improvements. | ||
| * | ||
| * These tests demonstrate that adapter caching provides measurable performance | ||
| * improvements when parsing multiple JSON files with the same Parser instance. | ||
| */ | ||
| class ParserPerformanceTest { | ||
| private val parser = Parser() | ||
|
|
||
| @Test | ||
| fun `parser should reuse adapters efficiently for multiple parsing calls`() { | ||
| val recordsJson = javaClass.getResourceAsStream("/records.json")!!.bufferedReader().readText() | ||
| val semanticJson = javaClass.getResourceAsStream("/semantic-2021-august.json")!!.bufferedReader().readText() | ||
|
|
||
| // Warm-up: Initialize adapters on first call | ||
| parser.parseRecords(recordsJson) | ||
| parser.parseSemanticTimeline(semanticJson) | ||
|
|
||
| // Measure performance of subsequent calls | ||
| val recordsTime = | ||
| measureTime { | ||
| repeat(10) { | ||
| val records = parser.parseRecords(recordsJson) | ||
| assertThat(records.locations).hasSize(12) | ||
| } | ||
| } | ||
|
|
||
| val semanticTime = | ||
| measureTime { | ||
| repeat(10) { | ||
| val timeline = parser.parseSemanticTimeline(semanticJson) | ||
| assertThat(timeline.timelineObjects).hasSize(125) | ||
| } | ||
| } | ||
|
|
||
| // Assert that parsing is reasonably fast (should be much faster than adapter creation overhead) | ||
| // These are reasonable benchmarks for cached adapters | ||
| assertThat(recordsTime.inWholeMilliseconds).isLessThan(500) // Should be very fast with cached adapters | ||
| assertThat(semanticTime.inWholeMilliseconds).isLessThan(1000) // Larger file, but still fast | ||
|
|
||
| println("Records parsing time (10x): ${recordsTime.inWholeMilliseconds}ms") | ||
| println("Semantic parsing time (10x): ${semanticTime.inWholeMilliseconds}ms") | ||
| } | ||
|
|
||
| @Test | ||
| fun `parser instance should be reusable across different JSON types`() { | ||
| val recordsJson = javaClass.getResourceAsStream("/records.json")!!.bufferedReader().readText() | ||
| val semanticJson = javaClass.getResourceAsStream("/semantic-2021-august.json")!!.bufferedReader().readText() | ||
| val settingsJson = javaClass.getResourceAsStream("/settings.json")!!.bufferedReader().readText() | ||
| val editsJson = javaClass.getResourceAsStream("/timeline-edits.json")!!.bufferedReader().readText() | ||
|
|
||
| // Parse different types with the same parser instance | ||
| val records = parser.parseRecords(recordsJson) | ||
| val timeline = parser.parseSemanticTimeline(semanticJson) | ||
| val settings = parser.parseSettings(settingsJson) | ||
| val edits = parser.parseTimelineEdits(editsJson) | ||
|
|
||
| // Verify all parsing succeeded | ||
| assertThat(records.locations).hasSize(12) | ||
| assertThat(timeline.timelineObjects).hasSize(125) | ||
| assertThat(settings.deviceSettings).isNotNull() | ||
| assertThat(edits.items).hasSize(3) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will take care of this being here later.