1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-19 19:51:35 +03:00
vimr/NvimView/Support/DrawerPerf/AppDelegate.swift

54 lines
1.2 KiB
Swift
Raw Normal View History

2020-08-19 01:09:13 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Cocoa
import GameKit
import os
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
2020-09-18 23:51:51 +03:00
@IBOutlet var window: NSWindow!
var result = [[[FontGlyphRun]]](repeating: [], count: count)
2020-08-19 01:09:13 +03:00
2020-09-18 23:51:51 +03:00
func applicationDidFinishLaunching(_: Notification) {
2020-08-19 01:09:13 +03:00
var results = [CFTimeInterval]()
let repeatCount = 5
2020-09-18 23:51:51 +03:00
for _ in 0..<repeatCount {
2020-08-19 01:09:13 +03:00
let rd = GKRandomDistribution(
2020-09-18 23:51:51 +03:00
randomSource: GKMersenneTwisterRandomSource(seed: 129_384_832),
2020-08-19 01:09:13 +03:00
lowestValue: 0,
highestValue: repeatCount - 1
)
2020-09-18 23:51:51 +03:00
let indices = (0..<count).map { _ in rd.nextInt() % 3 }
2020-08-19 01:09:13 +03:00
let time = self.measure {
2020-09-18 23:51:51 +03:00
for i in 0..<count { result[i] = self.perf.render(indices[i]) }
2020-08-19 01:09:13 +03:00
}
results.append(time)
}
self.log.default(
"\(results.reduce(0, +) / Double(results.count))s: \(results)"
)
NSApp.terminate(self)
}
private let perf = PerfTester()
2020-09-18 23:51:51 +03:00
private let log = OSLog(
subsystem: "com.qvacua.DrawerPerf",
category: "perf-tester"
)
2020-08-19 01:09:13 +03:00
private func measure(_ body: () -> Void) -> CFTimeInterval {
let start = CFAbsoluteTimeGetCurrent()
body()
return CFAbsoluteTimeGetCurrent() - start
}
}
private let count = 500