@@ -507,17 +507,17 @@ struct WireProtocolBenchmarks {
507507
508508 let jsonEncoder = JSONEncoder ( )
509509
510- let compactStart = CFAbsoluteTimeGetCurrent ( )
510+ let compactStart = Date ( ) . timeIntervalSinceReferenceDate
511511 for _ in 0 ..< Self . iterations {
512512 _ = wireEnvelope. encodeCompact ( )
513513 }
514- let compactDuration = CFAbsoluteTimeGetCurrent ( ) - compactStart
514+ let compactDuration = Date ( ) . timeIntervalSinceReferenceDate - compactStart
515515
516- let jsonStart = CFAbsoluteTimeGetCurrent ( )
516+ let jsonStart = Date ( ) . timeIntervalSinceReferenceDate
517517 for _ in 0 ..< Self . iterations {
518518 _ = try jsonEncoder. encode ( wireEnvelope)
519519 }
520- let jsonDuration = CFAbsoluteTimeGetCurrent ( ) - jsonStart
520+ let jsonDuration = Date ( ) . timeIntervalSinceReferenceDate - jsonStart
521521
522522 let speedup = jsonDuration / compactDuration
523523 print ( " Encoding \( Self . iterations) envelopes - Compact: \( String ( format: " %.3f " , compactDuration) ) s, JSON: \( String ( format: " %.3f " , jsonDuration) ) s, Speedup: \( String ( format: " %.2f " , speedup) ) x " )
@@ -540,18 +540,18 @@ struct WireProtocolBenchmarks {
540540 let compactData = wireEnvelope. encodeCompact ( )
541541 let jsonData = try JSONEncoder ( ) . encode ( wireEnvelope)
542542
543- let compactStart = CFAbsoluteTimeGetCurrent ( )
543+ let compactStart = Date ( ) . timeIntervalSinceReferenceDate
544544 for _ in 0 ..< Self . iterations {
545545 _ = try WireEnvelope . decodeCompact ( from: compactData)
546546 }
547- let compactDuration = CFAbsoluteTimeGetCurrent ( ) - compactStart
547+ let compactDuration = Date ( ) . timeIntervalSinceReferenceDate - compactStart
548548
549549 let jsonDecoder = JSONDecoder ( )
550- let jsonStart = CFAbsoluteTimeGetCurrent ( )
550+ let jsonStart = Date ( ) . timeIntervalSinceReferenceDate
551551 for _ in 0 ..< Self . iterations {
552552 _ = try jsonDecoder. decode ( WireEnvelope . self, from: jsonData)
553553 }
554- let jsonDuration = CFAbsoluteTimeGetCurrent ( ) - jsonStart
554+ let jsonDuration = Date ( ) . timeIntervalSinceReferenceDate - jsonStart
555555
556556 let speedup = jsonDuration / compactDuration
557557 print ( " Decoding \( Self . iterations) envelopes - Compact: \( String ( format: " %.3f " , compactDuration) ) s, JSON: \( String ( format: " %.3f " , jsonDuration) ) s, Speedup: \( String ( format: " %.2f " , speedup) ) x " )
@@ -574,19 +574,19 @@ struct WireProtocolBenchmarks {
574574 let jsonEncoder = JSONEncoder ( )
575575 let jsonDecoder = JSONDecoder ( )
576576
577- let compactStart = CFAbsoluteTimeGetCurrent ( )
577+ let compactStart = Date ( ) . timeIntervalSinceReferenceDate
578578 for _ in 0 ..< Self . iterations {
579579 let data = wireEnvelope. encodeCompact ( )
580580 _ = try WireEnvelope . decodeCompact ( from: data)
581581 }
582- let compactDuration = CFAbsoluteTimeGetCurrent ( ) - compactStart
582+ let compactDuration = Date ( ) . timeIntervalSinceReferenceDate - compactStart
583583
584- let jsonStart = CFAbsoluteTimeGetCurrent ( )
584+ let jsonStart = Date ( ) . timeIntervalSinceReferenceDate
585585 for _ in 0 ..< Self . iterations {
586586 let data = try jsonEncoder. encode ( wireEnvelope)
587587 _ = try jsonDecoder. decode ( WireEnvelope . self, from: data)
588588 }
589- let jsonDuration = CFAbsoluteTimeGetCurrent ( ) - jsonStart
589+ let jsonDuration = Date ( ) . timeIntervalSinceReferenceDate - jsonStart
590590
591591 let speedup = jsonDuration / compactDuration
592592 print ( " Round-trip \( Self . iterations) envelopes - Compact: \( String ( format: " %.3f " , compactDuration) ) s, JSON: \( String ( format: " %.3f " , jsonDuration) ) s, Speedup: \( String ( format: " %.2f " , speedup) ) x " )
@@ -617,21 +617,21 @@ struct WireProtocolBenchmarks {
617617 let jsonDecoder = JSONDecoder ( )
618618
619619 for _ in 0 ..< 1000 {
620- let start1 = CFAbsoluteTimeGetCurrent ( )
620+ let start1 = Date ( ) . timeIntervalSinceReferenceDate
621621 let compactData = wireEnvelope. encodeCompact ( )
622- compactEncodeTimes. append ( CFAbsoluteTimeGetCurrent ( ) - start1)
622+ compactEncodeTimes. append ( Date ( ) . timeIntervalSinceReferenceDate - start1)
623623
624- let start2 = CFAbsoluteTimeGetCurrent ( )
624+ let start2 = Date ( ) . timeIntervalSinceReferenceDate
625625 _ = try WireEnvelope . decodeCompact ( from: compactData)
626- compactDecodeTimes. append ( CFAbsoluteTimeGetCurrent ( ) - start2)
626+ compactDecodeTimes. append ( Date ( ) . timeIntervalSinceReferenceDate - start2)
627627
628- let start3 = CFAbsoluteTimeGetCurrent ( )
628+ let start3 = Date ( ) . timeIntervalSinceReferenceDate
629629 let jsonData = try jsonEncoder. encode ( wireEnvelope)
630- jsonEncodeTimes. append ( CFAbsoluteTimeGetCurrent ( ) - start3)
630+ jsonEncodeTimes. append ( Date ( ) . timeIntervalSinceReferenceDate - start3)
631631
632- let start4 = CFAbsoluteTimeGetCurrent ( )
632+ let start4 = Date ( ) . timeIntervalSinceReferenceDate
633633 _ = try jsonDecoder. decode ( WireEnvelope . self, from: jsonData)
634- jsonDecodeTimes. append ( CFAbsoluteTimeGetCurrent ( ) - start4)
634+ jsonDecodeTimes. append ( Date ( ) . timeIntervalSinceReferenceDate - start4)
635635 }
636636
637637 let compactEncodeAvg = compactEncodeTimes. reduce ( 0 , + ) / Double( compactEncodeTimes. count) * 1_000_000
0 commit comments