Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding SingletonSpeed demo

  • Loading branch information...
commit 58fe6ea279b649f5812ee9517e86aba42b52524d 0 parents
@bjhomer authored
237 SingletonSpeed/SingletonSpeed.xcodeproj/project.pbxproj
@@ -0,0 +1,237 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ B742E0BD1434B4EA005A06FF /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B742E0BC1434B4EA005A06FF /* Foundation.framework */; };
+ B742E0C01434B4EA005A06FF /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B742E0BF1434B4EA005A06FF /* main.m */; };
+ B742E0C41434B4EA005A06FF /* SingletonSpeed.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = B742E0C31434B4EA005A06FF /* SingletonSpeed.1 */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+ B742E0B61434B4E9005A06FF /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ B742E0C41434B4EA005A06FF /* SingletonSpeed.1 in CopyFiles */,
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+ B742E0B81434B4EA005A06FF /* SingletonSpeed */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = SingletonSpeed; sourceTree = BUILT_PRODUCTS_DIR; };
+ B742E0BC1434B4EA005A06FF /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ B742E0BF1434B4EA005A06FF /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ B742E0C21434B4EA005A06FF /* SingletonSpeed-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SingletonSpeed-Prefix.pch"; sourceTree = "<group>"; };
+ B742E0C31434B4EA005A06FF /* SingletonSpeed.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = SingletonSpeed.1; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ B742E0B51434B4E9005A06FF /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ B742E0BD1434B4EA005A06FF /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ B742E0AD1434B4E8005A06FF = {
+ isa = PBXGroup;
+ children = (
+ B742E0BE1434B4EA005A06FF /* SingletonSpeed */,
+ B742E0BB1434B4EA005A06FF /* Frameworks */,
+ B742E0B91434B4EA005A06FF /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ B742E0B91434B4EA005A06FF /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ B742E0B81434B4EA005A06FF /* SingletonSpeed */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ B742E0BB1434B4EA005A06FF /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ B742E0BC1434B4EA005A06FF /* Foundation.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ B742E0BE1434B4EA005A06FF /* SingletonSpeed */ = {
+ isa = PBXGroup;
+ children = (
+ B742E0BF1434B4EA005A06FF /* main.m */,
+ B742E0C31434B4EA005A06FF /* SingletonSpeed.1 */,
+ B742E0C11434B4EA005A06FF /* Supporting Files */,
+ );
+ path = SingletonSpeed;
+ sourceTree = "<group>";
+ };
+ B742E0C11434B4EA005A06FF /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ B742E0C21434B4EA005A06FF /* SingletonSpeed-Prefix.pch */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ B742E0B71434B4E9005A06FF /* SingletonSpeed */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = B742E0C71434B4EA005A06FF /* Build configuration list for PBXNativeTarget "SingletonSpeed" */;
+ buildPhases = (
+ B742E0B41434B4E9005A06FF /* Sources */,
+ B742E0B51434B4E9005A06FF /* Frameworks */,
+ B742E0B61434B4E9005A06FF /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = SingletonSpeed;
+ productName = SingletonSpeed;
+ productReference = B742E0B81434B4EA005A06FF /* SingletonSpeed */;
+ productType = "com.apple.product-type.tool";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ B742E0AF1434B4E9005A06FF /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0420;
+ ORGANIZATIONNAME = Instructure;
+ };
+ buildConfigurationList = B742E0B21434B4E9005A06FF /* Build configuration list for PBXProject "SingletonSpeed" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = B742E0AD1434B4E8005A06FF;
+ productRefGroup = B742E0B91434B4EA005A06FF /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ B742E0B71434B4E9005A06FF /* SingletonSpeed */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+ B742E0B41434B4E9005A06FF /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ B742E0C01434B4EA005A06FF /* main.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+ B742E0C51434B4EA005A06FF /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ COPY_PHASE_STRIP = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ B742E0C61434B4EA005A06FF /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.7;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+ B742E0C81434B4EA005A06FF /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "SingletonSpeed/SingletonSpeed-Prefix.pch";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ B742E0C91434B4EA005A06FF /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "SingletonSpeed/SingletonSpeed-Prefix.pch";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ B742E0B21434B4E9005A06FF /* Build configuration list for PBXProject "SingletonSpeed" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ B742E0C51434B4EA005A06FF /* Debug */,
+ B742E0C61434B4EA005A06FF /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ B742E0C71434B4EA005A06FF /* Build configuration list for PBXNativeTarget "SingletonSpeed" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ B742E0C81434B4EA005A06FF /* Debug */,
+ B742E0C91434B4EA005A06FF /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = B742E0AF1434B4E9005A06FF /* Project object */;
+}
7 SingletonSpeed/SingletonSpeed.xcodeproj/project.xcworkspace/contents.xcworkspacedata
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Workspace
+ version = "1.0">
+ <FileRef
+ location = "self:SingletonSpeed.xcodeproj">
+ </FileRef>
+</Workspace>
7 SingletonSpeed/SingletonSpeed/SingletonSpeed-Prefix.pch
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'SingletonSpeed' target in the 'SingletonSpeed' project
+//
+
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+#endif
79 SingletonSpeed/SingletonSpeed/SingletonSpeed.1
@@ -0,0 +1,79 @@
+.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
+.\"See Also:
+.\"man mdoc.samples for a complete listing of options
+.\"man mdoc for the short list of editing options
+.\"/usr/share/misc/mdoc.template
+.Dd 9/29/11 \" DATE
+.Dt SingletonSpeed 1 \" Program name and manual section number
+.Os Darwin
+.Sh NAME \" Section Header - required - don't modify
+.Nm SingletonSpeed,
+.\" The following lines are read in generating the apropos(man -k) database. Use only key
+.\" words here as the database is built based on the words here and in the .ND line.
+.Nm Other_name_for_same_program(),
+.Nm Yet another name for the same program.
+.\" Use .Nm macro to designate other names for the documented program.
+.Nd This line parsed for whatis database.
+.Sh SYNOPSIS \" Section Header - required - don't modify
+.Nm
+.Op Fl abcd \" [-abcd]
+.Op Fl a Ar path \" [-a path]
+.Op Ar file \" [file]
+.Op Ar \" [file ...]
+.Ar arg0 \" Underlined argument - use .Ar anywhere to underline
+arg2 ... \" Arguments
+.Sh DESCRIPTION \" Section Header - required - don't modify
+Use the .Nm macro to refer to your program throughout the man page like such:
+.Nm
+Underlining is accomplished with the .Ar macro like this:
+.Ar underlined text .
+.Pp \" Inserts a space
+A list of items with descriptions:
+.Bl -tag -width -indent \" Begins a tagged list
+.It item a \" Each item preceded by .It macro
+Description of item a
+.It item b
+Description of item b
+.El \" Ends the list
+.Pp
+A list of flags and their descriptions:
+.Bl -tag -width -indent \" Differs from above in tag removed
+.It Fl a \"-a flag as a list item
+Description of -a flag
+.It Fl b
+Description of -b flag
+.El \" Ends the list
+.Pp
+.\" .Sh ENVIRONMENT \" May not be needed
+.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
+.\" .It Ev ENV_VAR_1
+.\" Description of ENV_VAR_1
+.\" .It Ev ENV_VAR_2
+.\" Description of ENV_VAR_2
+.\" .El
+.Sh FILES \" File used or created by the topic of the man page
+.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
+.It Pa /usr/share/file_name
+FILE_1 description
+.It Pa /Users/joeuser/Library/really_long_file_name
+FILE_2 description
+.El \" Ends the list
+.\" .Sh DIAGNOSTICS \" May not be needed
+.\" .Bl -diag
+.\" .It Diagnostic Tag
+.\" Diagnostic informtion here.
+.\" .It Diagnostic Tag
+.\" Diagnostic informtion here.
+.\" .El
+.Sh SEE ALSO
+.\" List links in ascending order by section, alphabetically within a section.
+.\" Please do not reference files that do not exist without filing a bug report
+.Xr a 1 ,
+.Xr b 1 ,
+.Xr c 1 ,
+.Xr a 2 ,
+.Xr b 2 ,
+.Xr a 3 ,
+.Xr b 3
+.\" .Sh BUGS \" Document known, unremedied bugs
+.\" .Sh HISTORY \" Document history if command behaves in a unique manner
128 SingletonSpeed/SingletonSpeed/main.m
@@ -0,0 +1,128 @@
+//
+// main.m
+// SingletonSpeed
+//
+// Created by BJ Homer on 9/29/11.
+// Copyright (c) 2011 Instructure. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface Test : NSObject
++ (id)synchronizedInstance;
++ (id)dispatchOnceInstance;
+@end
+
+static id synchronizedVar = nil;
+static id dispatchVar = nil;
+
+@implementation Test
+
++ (id)synchronizedInstance {
+ @synchronized(self) {
+ if (!synchronizedVar) {
+ synchronizedVar = [[Test alloc] init];
+ }
+ }
+ return synchronizedVar;
+}
+
++ (id)dispatchOnceInstance {
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ dispatchVar = [[Test alloc] init];
+ });
+ return dispatchVar;
+}
+
+@end
+
+#define ITERATIONS 10000000
+
+CFTimeInterval singleThreadedSynchronized(void);
+CFTimeInterval singleThreadedSynchronized(void) {
+ CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
+
+ for (int i=0; i<ITERATIONS; ++i) {
+ [Test synchronizedInstance];
+ }
+ CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
+ return end - start;
+}
+
+CFTimeInterval singleThreadedDispatch(void);
+CFTimeInterval singleThreadedDispatch(void) {
+ CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
+
+ for (int i=0; i<ITERATIONS; ++i) {
+ [Test dispatchOnceInstance];
+ }
+ CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
+ return end - start;
+}
+
+CFTimeInterval multiThreadedSynchronized(void);
+CFTimeInterval multiThreadedSynchronized(void) {
+ CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
+
+ int numTasks = 10;
+ dispatch_group_t group = dispatch_group_create();
+ for (int i=0; i<numTasks; ++i) {
+ dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ for (int i=0; i<ITERATIONS/numTasks; ++i) {
+ [Test synchronizedInstance];
+ }
+ });
+ }
+ dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
+
+ CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
+ return end - start;
+}
+
+CFTimeInterval multiThreadedDispatch(void);
+CFTimeInterval multiThreadedDispatch(void) {
+ CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
+
+ int numTasks = 10;
+ dispatch_group_t group = dispatch_group_create();
+ for (int i=0; i<numTasks; ++i) {
+ dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ for (int i=0; i<ITERATIONS/numTasks; ++i) {
+ [Test dispatchOnceInstance];
+ }
+ });
+ }
+ dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
+
+ CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
+ return end - start;
+}
+
+int main (int argc, const char * argv[])
+{
+
+ @autoreleasepool {
+
+ CFTimeInterval a = singleThreadedSynchronized();
+ CFTimeInterval b = singleThreadedDispatch();
+ CFTimeInterval c = multiThreadedSynchronized();
+ CFTimeInterval d = multiThreadedDispatch();
+
+ NSLog(@"\n"
+ @"Single threaded results\n"
+ @"-----------------------\n"
+ @" @synchronized: %0.4f seconds\n"
+ @" dispatch_once: %0.4f seconds\n"
+ @"\n"
+ @"Multi threaded results\n"
+ @"----------------------\n"
+ @" @synchronized: %0.4f seconds\n"
+ @" dispatch_once: %0.4f seconds\n",
+ a, b, c, d);
+
+
+ }
+ return 0;
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.