分散関数呼び出し
Posted feedbacks - Objective-C
CPU: 1.83 GHz Intel Core Duo メモリ: 2 GB 実行: 同一サーバ内 1万回の実行時間: 1.936秒
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 84 85 | //--------------------------------------------------------------------------------
//サーバ側のソースコード
//ソースファイルのエンコーディングはUTF-8にしてください
//--------------------------------------------------------------------------------
#import <Foundation/Foundation.h>
@interface Server : NSObject {
}
- (NSString*)priceString:(NSNumber*)listPrice :(NSNumber*)discount;
@end
@implementation Server
- (NSString*)insertComma:(unsigned)number {
NSMutableString* result = [NSMutableString stringWithString:
[[NSNumber numberWithUnsignedInt:number] stringValue]];
int length = [result length];
while ( length > 3 ) {
length -= 3;
[result insertString:@"," atIndex:length];
}
return result;
}
- (NSString*)priceString:(NSNumber*)listPrice :(NSNumber*)discount {
NSString* format = [NSString stringWithUTF8String: "販売価格 %@円 (定価%@円から%d%%%%引き)"];
unsigned unsignedListPrice = [listPrice unsignedIntValue];
unsigned unsignedDiscount = [discount unsignedIntValue];
unsigned unsignedRetailPrice = unsignedListPrice * ( 100 - unsignedDiscount ) / 100;
NSString* listPriceString = [self insertComma:unsignedListPrice];
NSString* retailPriceString = [self insertComma:unsignedRetailPrice];
return [NSString stringWithFormat: format, retailPriceString, listPriceString, unsignedDiscount];
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Server* server = [[[Server alloc] init] autorelease];
NSConnection* connection = [NSConnection defaultConnection];
[connection setRootObject:server];
if ( [connection registerName:@"server"] )
[[NSRunLoop currentRunLoop] run];
[pool release];
return 0;
}
//--------------------------------------------------------------------------------
//クライアント側のソースコード
//コンパイルオプション:-std=gnu99
//--------------------------------------------------------------------------------
#import <Foundation/Foundation.h>
@protocol ServerProtocol
- (NSString*)priceString:(NSNumber*)listPrice :(NSNumber*)discount;
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSDistantObject* distantObject = [NSConnection
rootProxyForConnectionWithRegisteredName:@"server" host:nil];
[distantObject setProtocolForProxy:@protocol(ServerProtocol)];
NSNumber* listPrice = [NSNumber numberWithInt:2000];
NSNumber* discount = [NSNumber numberWithInt:20];
NSLog( @"start" );
for ( int i = 0; i < 10000; i++ )
[distantObject performSelector:@selector(priceString::) withObject:listPrice withObject:discount];
NSLog( @"end" );
[pool release];
return 0;
}
|

沢渡 みかげ
#3401()
Rating0/0=0.00
[ reply ]