1
/* Test/example program for the base library
3
Copyright (C) 2005 Free Software Foundation, Inc.
5
Copying and distribution of this file, with or without modification,
6
are permitted in any medium without royalty provided the copyright
7
notice and this notice are preserved.
9
This file is part of the GNUstep Base Library.
11
#include <Foundation/NSDictionary.h>
12
#include <Foundation/NSEnumerator.h>
13
#include <Foundation/NSString.h>
14
#include <Foundation/NSArray.h>
15
#include <Foundation/NSValue.h>
16
#include <Foundation/NSDate.h>
17
#include <Foundation/NSAutoreleasePool.h>
21
main(int argc, char** argv, char** envp)
23
NSString *strs[100000];
24
NSMutableDictionary *dict;
27
NSAutoreleasePool *arp;
28
id a, b; /* dictionaries */
33
id o1, o2, o3, o4, o5, o6;
34
NSMutableDictionary *d1, *d2;
36
arp = [NSAutoreleasePool new];
38
o1 = [[NSNumber numberWithInt:1] stringValue];
39
o2 = [[NSNumber numberWithInt:2] stringValue];
40
o3 = [[NSNumber numberWithInt:3] stringValue];
41
o4 = [[NSNumber numberWithInt:4] stringValue];
42
o5 = [[NSNumber numberWithInt:5] stringValue];
43
o6 = [[NSNumber numberWithInt:6] stringValue];
45
d1 = [[NSMutableDictionary new] autorelease];
46
[d1 setObject:o1 forKey:o1];
47
[d1 setObject:o2 forKey:o2];
48
[d1 setObject:o3 forKey:o3];
50
d2 = [[NSMutableDictionary new] autorelease];
51
[d2 setObject:o4 forKey:o4];
52
[d2 setObject:o5 forKey:o5];
53
[d2 setObject:o6 forKey:o6];
55
[d1 addEntriesFromDictionary: d2];
57
enumerator = [d1 objectEnumerator];
58
while ((b = [enumerator nextObject]))
59
printf("%s ", [b cString]);
62
//behavior_set_debug(0);
64
objects = [NSArray arrayWithObjects:
65
@"vache", @"poisson", @"cheval", @"poulet", nil];
66
keys = [NSArray arrayWithObjects:
67
@"cow", @"fish", @"horse", @"chicken", nil];
68
a = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
69
b = [NSDictionary dictionaryWithObjectsAndKeys:
79
printf("Match is %d\n", [a isEqual: b]);
81
printf("NSDictionary has count %d\n", [a count]);
83
printf("Object at key %s is %s\n",
85
[[a objectForKey:key] cString]);
87
assert([a count] == [[a allValues] count]);
89
enumerator = [a objectEnumerator];
90
while ((b = [enumerator nextObject]))
91
printf("%s ", [b cString]);
94
enumerator = [a keyEnumerator];
95
while ((b = [enumerator nextObject]))
96
printf("%s ", [b cString]);
105
[b setObject:@"formi" forKey:@"ant"];
106
[b removeObjectForKey:@"horse"];
109
when = [NSDate date];
110
dict = [NSMutableDictionary dictionaryWithCapacity: 100];
111
for (i = 0; i < 10; i++)
113
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
114
[dict setObject: strs[i] forKey: strs[i]];
116
printf(" 10 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
117
printf("%s\n", [[[dict allKeys] description] cString]);
119
when = [NSDate date];
120
for (i = 0; i < 100000; i++) {
121
for (j = 0; j < 10; j++) {
122
NSString *val = [dict objectForKey: strs[j]];
125
printf(" 10 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
128
arp = [NSAutoreleasePool new];
130
when = [NSDate date];
131
dict = [NSMutableDictionary dictionaryWithCapacity: 100];
132
for (i = 0; i < 100; i++)
134
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
135
[dict setObject: strs[i] forKey: strs[i]];
137
printf(" 100 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
139
when = [NSDate date];
140
for (i = 0; i < 10000; i++) {
141
for (j = 0; j < 100; j++) {
142
NSString *val = [dict objectForKey: strs[j]];
145
printf(" 100 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
148
arp = [NSAutoreleasePool new];
150
when = [NSDate date];
151
dict = [NSMutableDictionary dictionaryWithCapacity: 1000];
152
for (i = 0; i < 1000; i++)
154
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
155
[dict setObject: strs[i] forKey: strs[i]];
157
printf(" 1000 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
159
when = [NSDate date];
160
for (i = 0; i < 1000; i++) {
161
for (j = 0; j < 1000; j++) {
162
NSString *val = [dict objectForKey: strs[j]];
165
printf(" 1000 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
168
arp = [NSAutoreleasePool new];
170
when = [NSDate date];
171
dict = [NSMutableDictionary dictionaryWithCapacity: 10000];
172
for (i = 0; i < 10000; i++)
174
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
175
[dict setObject: strs[i] forKey: strs[i]];
177
printf(" 10000 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
179
when = [NSDate date];
180
for (i = 0; i < 100; i++) {
181
for (j = 0; j < 10000; j++) {
182
NSString *val = [dict objectForKey: strs[j]];
185
printf(" 10000 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
188
arp = [NSAutoreleasePool new];
190
when = [NSDate date];
191
dict = [NSMutableDictionary dictionaryWithCapacity: 100000];
192
for (i = 0; i < 100000; i++)
194
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
195
[dict setObject: strs[i] forKey: strs[i]];
197
printf("100000 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
199
when = [NSDate date];
200
for (i = 0; i < 10; i++) {
201
for (j = 0; j < 100000; j++) {
202
NSString *val = [dict objectForKey: strs[j]];
205
printf("100000 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);