-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathConsoleLoggerBenchmarks.swift
More file actions
83 lines (78 loc) 路 2.73 KB
/
Copy pathConsoleLoggerBenchmarks.swift
File metadata and controls
83 lines (78 loc) 路 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import Benchmark
import ConsoleLogger
import Logging
let benchmarks: @Sendable () -> Void = {
Benchmark.defaultConfiguration = .init(
metrics: [.peakMemoryResident, .mallocCountTotal],
thresholds: [
.peakMemoryResident: .init(
// Tolerate up to 4% of difference compared to the threshold.
relative: [.p90: 4],
// Tolerate up to one million bytes of difference compared to the threshold.
absolute: [.p90: 1_100_000]
),
.mallocCountTotal: .init(
// Tolerate up to 1% of difference compared to the threshold.
relative: [.p90: 1],
// Tolerate up to 2 malloc calls of difference compared to the threshold.
absolute: [.p90: 2]
),
]
)
Benchmark(
"Logging",
configuration: .init(
setup: {
LoggingSystem.bootstrap(
{ label, provider in
ConsoleLogger(label: label)
},
metadataProvider: .init {
["provided1": "from metadata provider", "provided2": "another metadata provider"]
}
)
}
)
) { benchmark in
var logger = Logger(label: "codes.vapor.console")
logger.logLevel = .trace
logger[metadataKey: "value"] = "one"
for _ in benchmark.scaledIterations {
logger.info(
"Info",
metadata: ["from-log": "value", "also-from-log": "other"]
)
}
}
Benchmark(
"LoggerFragmentBuilder",
configuration: .init(
setup: {
LoggingSystem.bootstrap(
metadataProvider: .init {
["provided1": "from metadata provider", "provided2": "another metadata provider"]
}
) {
// This is the default logger fragment, but built using LoggerFragmentBuilder
SpacedFragment {
LabelFragment().maxLevel(.trace)
LevelFragment()
MessageFragment()
MetadataFragment()
SourceLocationFragment().maxLevel(.debug)
}
}
}
)
) { benchmark in
var logger = Logger(label: "codes.vapor.console")
logger.logLevel = .trace
logger[metadataKey: "value"] = "one"
for _ in benchmark.scaledIterations {
logger.info(
"Info",
metadata: ["from-log": "value", "also-from-log": "other"]
)
}
}
}