Merge remote-tracking branches 'github/pr/30{62,57,55,51,50}'
Merge a bunch of changes from terry, translations, and me
Terry Yiu (4):
Add NIP-05 favicon to profile names and NIP-05 web of trust feed
Fix quotes view header alignment
Export strings for translation
Rename Bitcoin Beach wallet to Blink
Transifex (11):
Translate Localizable.strings in th
Translate Localizable.strings in th
Translate Localizable.strings in nl
Translate Localizable.strings in de
Translate Localizable.stringsdict in de
Translate Localizable.stringsdict in de
Translate Localizable.strings in th
Translate Localizable.strings in th
Translate Localizable.strings in th
Translate Localizable.strings in th
Translate Localizable.strings in th
William Casarin (2):
perf: don't use regex in trim_{prefix,suffix}
This commit is contained in:
72
damusTests/Benchmarking.swift
Normal file
72
damusTests/Benchmarking.swift
Normal file
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// Benchmarking.swift
|
||||
// damusTests
|
||||
//
|
||||
// Created by William Casarin on 3/6/25.
|
||||
//
|
||||
|
||||
import Testing
|
||||
import XCTest
|
||||
@testable import damus
|
||||
|
||||
class BenchmarkingTests: XCTestCase {
|
||||
|
||||
// Old regex-based implementations for comparison
|
||||
func trim_suffix_regex(_ str: String) -> String {
|
||||
return str.replacingOccurrences(of: "\\s+$", with: "", options: .regularExpression)
|
||||
}
|
||||
|
||||
func trim_prefix_regex(_ str: String) -> String {
|
||||
return str.replacingOccurrences(of: "^\\s+", with: "", options: .regularExpression)
|
||||
}
|
||||
|
||||
// Test strings with different characteristics
|
||||
lazy var testStrings: [String] = [
|
||||
" Hello World ", // Simple whitespace
|
||||
" \n\t Hello World \n\t ", // Mixed whitespace
|
||||
String(repeating: " ", count: 1000) + "Hello", // Large prefix
|
||||
"Hello" + String(repeating: " ", count: 1000), // Large suffix
|
||||
String(repeating: " ", count: 500) + "Hello" + String(repeating: " ", count: 500) // Both
|
||||
]
|
||||
|
||||
func testTrimSuffixRegexPerformance() throws {
|
||||
measure {
|
||||
for str in testStrings {
|
||||
_ = trim_suffix_regex(str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testTrimSuffixNewPerformance() throws {
|
||||
measure {
|
||||
for str in testStrings {
|
||||
_ = trim_suffix(str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testTrimPrefixRegexPerformance() throws {
|
||||
measure {
|
||||
for str in testStrings {
|
||||
_ = trim_prefix_regex(str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testTrimPrefixNewPerformance() throws {
|
||||
measure {
|
||||
for str in testStrings {
|
||||
_ = trim_prefix(str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testTrimFunctionCorrectness() throws {
|
||||
// Verify that both implementations produce the same results
|
||||
for str in testStrings {
|
||||
XCTAssertEqual(trim_suffix(str), trim_suffix_regex(str), "New trim_suffix implementation produces different results")
|
||||
XCTAssertEqual(trim_prefix(str), trim_prefix_regex(str), "New trim_prefix implementation produces different results")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ func generate_test_damus_state(
|
||||
video: .init(),
|
||||
ndb: ndb,
|
||||
quote_reposts: .init(our_pubkey: our_pubkey),
|
||||
emoji_provider: DefaultEmojiProvider(showAllVariations: false)
|
||||
emoji_provider: DefaultEmojiProvider(showAllVariations: false),
|
||||
favicon_cache: .init()
|
||||
)
|
||||
|
||||
return damus
|
||||
|
||||
39
damusTests/NIP05DomainTimelineHeaderViewTests.swift
Normal file
39
damusTests/NIP05DomainTimelineHeaderViewTests.swift
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// NIP05DomainTimelineHeaderViewTests.swift
|
||||
// damusTests
|
||||
//
|
||||
// Created by Terry Yiu on 5/23/25.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import damus
|
||||
|
||||
final class NIP05DomainTimelineHeaderViewTests: XCTestCase {
|
||||
|
||||
let enUsLocale = Locale(identifier: "en-US")
|
||||
|
||||
func testFriendsOfFriendsString() throws {
|
||||
let pk1 = test_pubkey
|
||||
let pk2 = test_pubkey_2
|
||||
let pk3 = Pubkey(hex: "b42e44b555013239a0d5dcdb09ebde0857cd8a5a57efbba5a2b6ac78833cb9f0")!
|
||||
let pk4 = Pubkey(hex: "cc590e46363d0fa66bb27081368d01f169b8ffc7c614629d4e9eef6c88b38670")!
|
||||
let pk5 = Pubkey(hex: "f2aa579bb998627e04a8f553842a09446360c9d708c6141dd119c479f6ab9d29")!
|
||||
|
||||
let ndb = Ndb(path: Ndb.db_path)!
|
||||
|
||||
let damus_name = "17ldvg64:nq5mhr77"
|
||||
XCTAssertEqual(friendsOfFriendsString([pk1], ndb: ndb, locale: enUsLocale), "Notes from \(damus_name)")
|
||||
XCTAssertEqual(friendsOfFriendsString([pk1, pk2], ndb: ndb, locale: enUsLocale), "Notes from \(damus_name) & 1rppft3m:4qxhsgnj")
|
||||
XCTAssertEqual(friendsOfFriendsString([pk1, pk2, pk3], ndb: ndb, locale: enUsLocale), "Notes from \(damus_name), 1rppft3m:4qxhsgnj & 1kshyfd2:cq04aze0")
|
||||
XCTAssertEqual(friendsOfFriendsString([pk1, pk2, pk3, pk4,], ndb: ndb, locale: enUsLocale), "Notes from \(damus_name), 1rppft3m:4qxhsgnj, 1kshyfd2:cq04aze0 & 1 other in your trusted network")
|
||||
XCTAssertEqual(friendsOfFriendsString([pk1, pk2, pk3, pk4, pk5], ndb: ndb, locale: enUsLocale), "Notes from \(damus_name), 1rppft3m:4qxhsgnj, 1kshyfd2:cq04aze0 & 2 others in your trusted network")
|
||||
|
||||
let pubkeys = [pk1, pk2, pk3, pk4, pk5, pk1, pk2, pk3, pk4, pk5]
|
||||
Bundle.main.localizations.map { Locale(identifier: $0) }.forEach {
|
||||
for count in 1...10 {
|
||||
XCTAssertNoThrow(friendsOfFriendsString(pubkeys.prefix(count).map { $0 }, ndb: ndb, locale: $0))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user