Skip to content

Instantly share code, notes, and snippets.

@netskink
Created March 24, 2016 11:51
Show Gist options
  • Save netskink/7917e8013c767de6a8fe to your computer and use it in GitHub Desktop.
Save netskink/7917e8013c767de6a8fe to your computer and use it in GitHub Desktop.
import XCTest
@testable import SimpleApp
class SimpleAppRandomPerfTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testPerformanceCStyleForLoop() {
print("****** This is a performance test for a c style for loop ********");
self.measureBlock {
// How long does it take to add 1000 items by odd counts using a C-style for loop
var sum : Int;
var i : Int;
sum = 0;
for (i=0; i<1000000; i++) {
if ( i % 2 == 0 ) {
sum = sum + i;
}
}
print("sum = ", sum);
}
}
func testPerformanceSwiftStyleForLoop() {
print("****** This is a performance test for a swift style for loop ********");
self.measureBlock {
// How long does it take to add 1000 items by odd counts using a C-style for loop
var sum : Int;
sum = 0;
for i in 0.stride(to:1000000, by: 2) {
sum = sum + i;
}
print("sum = ", sum);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment