Skip to content

Commit b99e82b

Browse files
committed
Initial commit
0 parents  commit b99e82b

File tree

872 files changed

+487537
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

872 files changed

+487537
-0
lines changed

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Visual Studio Code
2+
.vscode
3+
4+
# Android Studio, Gradle
5+
*.iml
6+
.gradle
7+
.idea
8+
.settings
9+
.project
10+
.classpath
11+
.DS_Store
12+
.externalNativeBuild
13+
14+
# Xcode
15+
*.pbxuser
16+
xcuserdata
17+
xcuserdata/*
18+
*.xcworkspace/*
19+
*.xcworkspace

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "sqlcipher"]
2+
path = sqlcipher
3+
url = https://github.com/Tencent/sqlcipher.git
4+
[submodule "openssl"]
5+
path = openssl
6+
url = https://github.com/openssl/openssl.git

Apple/Benchmark/WCTBenchmarkObject.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* WCDB available.
4+
*
5+
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
6+
* All rights reserved.
7+
*
8+
* Licensed under the BSD 3-Clause License (the "License"); you may not use
9+
* this file except in compliance with the License. You may obtain a copy of
10+
* the License at
11+
*
12+
* https://opensource.org/licenses/BSD-3-Clause
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#import <Foundation/Foundation.h>
22+
#import <WCDB/WCDB.h>
23+
24+
@interface WCTBenchmarkObject : NSObject<WCTTableCoding>
25+
26+
@property int intValue;
27+
@property(retain) NSString* stringValue;
28+
29+
WCDB_PROPERTY(intValue)
30+
WCDB_PROPERTY(stringValue)
31+
32+
@end

Apple/Benchmark/WCTBenchmarkObject.mm

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* WCDB available.
4+
*
5+
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
6+
* All rights reserved.
7+
*
8+
* Licensed under the BSD 3-Clause License (the "License"); you may not use
9+
* this file except in compliance with the License. You may obtain a copy of
10+
* the License at
11+
*
12+
* https://opensource.org/licenses/BSD-3-Clause
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#import "WCTBenchmarkObject.h"
22+
23+
@implementation WCTBenchmarkObject
24+
25+
WCDB_IMPLEMENTATION(WCTBenchmarkObject)
26+
WCDB_SYNTHESIZE(WCTBenchmarkObject, intValue)
27+
WCDB_SYNTHESIZE(WCTBenchmarkObject, stringValue)
28+
29+
WCDB_PRIMARY(WCTBenchmarkObject, intValue)
30+
31+
@end
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* WCDB available.
4+
*
5+
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
6+
* All rights reserved.
7+
*
8+
* Licensed under the BSD 3-Clause License (the "License"); you may not use
9+
* this file except in compliance with the License. You may obtain a copy of
10+
* the License at
11+
*
12+
* https://opensource.org/licenses/BSD-3-Clause
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#import <Foundation/Foundation.h>
22+
23+
@interface WCTBenchmarkStaticstic : NSObject
24+
25+
- (void)start;
26+
- (void)tick;
27+
- (void)stop;
28+
29+
- (NSArray<NSNumber*>*)getElapseTimes;
30+
- (void)report;
31+
32+
@end
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* WCDB available.
4+
*
5+
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
6+
* All rights reserved.
7+
*
8+
* Licensed under the BSD 3-Clause License (the "License"); you may not use
9+
* this file except in compliance with the License. You may obtain a copy of
10+
* the License at
11+
*
12+
* https://opensource.org/licenses/BSD-3-Clause
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#import "WCTBenchmarkStaticstic.h"
22+
#import <mach/mach_time.h>
23+
24+
@implementation WCTBenchmarkStaticstic {
25+
NSMutableArray<NSNumber*>* _ticks;
26+
}
27+
28+
- (instancetype)init
29+
{
30+
if (self = [super init]) {
31+
_ticks = [[NSMutableArray alloc] init];
32+
}
33+
return self;
34+
}
35+
36+
- (void)start
37+
{
38+
[self tick];
39+
}
40+
41+
- (void)tick
42+
{
43+
NSNumber* time = [NSNumber numberWithLongLong:mach_absolute_time()];
44+
[_ticks addObject:time];
45+
}
46+
47+
- (void)stop
48+
{
49+
[self tick];
50+
}
51+
52+
- (void)report
53+
{
54+
for (NSNumber* elapse in [self getElapseTimes]) {
55+
NSLog(@"Tick cost : %f ms", elapse.doubleValue);
56+
}
57+
}
58+
59+
- (NSArray<NSNumber*>*)getElapseTimes
60+
{
61+
NSMutableArray<NSNumber*>* elapseTimes = [[NSMutableArray alloc] init];
62+
mach_timebase_info_data_t info;
63+
mach_timebase_info(&info);
64+
65+
uint64_t lastTick = 0;
66+
for (NSUInteger i = 0; i < _ticks.count; ++i) {
67+
uint64_t currentTick = _ticks[i].longLongValue;
68+
if (i>0) {
69+
uint64_t elapse = currentTick-lastTick;
70+
double ns = (double)elapse * (double)info.numer / (double)info.denom;
71+
double ms = ns/1000/1000;
72+
[elapseTimes addObject:[NSNumber numberWithDouble:ms]];
73+
}
74+
lastTick = currentTick;
75+
}
76+
return elapseTimes;
77+
}
78+
79+
@end

Apple/Benchmark/benchmark_main.mm

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* WCDB available.
4+
*
5+
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
6+
* All rights reserved.
7+
*
8+
* Licensed under the BSD 3-Clause License (the "License"); you may not use
9+
* this file except in compliance with the License. You may obtain a copy of
10+
* the License at
11+
*
12+
* https://opensource.org/licenses/BSD-3-Clause
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#import <Foundation/Foundation.h>
22+
#import "benchmark_normal.h"
23+
int main(int argc, const char * argv[]) {
24+
#warning TODO Perfect benchmark works
25+
NSString* machPath = [NSString stringWithUTF8String:argv[0]];
26+
NSString* baseDirectory = [[machPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"SampleDB"];
27+
NSLog(@"Base Directory: %@", baseDirectory);
28+
benchmark_normal(baseDirectory);
29+
return 0;
30+
}

Apple/Benchmark/benchmark_normal.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* WCDB available.
4+
*
5+
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
6+
* All rights reserved.
7+
*
8+
* Licensed under the BSD 3-Clause License (the "License"); you may not use
9+
* this file except in compliance with the License. You may obtain a copy of
10+
* the License at
11+
*
12+
* https://opensource.org/licenses/BSD-3-Clause
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#import <Foundation/Foundation.h>
22+
23+
void benchmark_normal(NSString* baseDirectory);

Apple/Benchmark/benchmark_normal.mm

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making
3+
* WCDB available.
4+
*
5+
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
6+
* All rights reserved.
7+
*
8+
* Licensed under the BSD 3-Clause License (the "License"); you may not use
9+
* this file except in compliance with the License. You may obtain a copy of
10+
* the License at
11+
*
12+
* https://opensource.org/licenses/BSD-3-Clause
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
#import "benchmark_normal.h"
22+
#import "WCTBenchmarkStaticstic.h"
23+
#import "WCTBenchmarkObject.h"
24+
25+
void benchmark_normal(NSString* baseDirectory)
26+
{
27+
NSString* className = NSStringFromClass(WCTBenchmarkObject.class);
28+
NSString* path = [baseDirectory stringByAppendingPathComponent:className];
29+
NSString* tableName = className;
30+
WCTDataBase* database = [[WCTDataBase alloc] initWithPath:path];
31+
[database close:^{
32+
[database removeFilesWithError:nil];
33+
}];
34+
35+
{
36+
BOOL ret = [database createTableAndIndexesOfName:tableName
37+
withClass:WCTBenchmarkObject.class];
38+
assert(ret);
39+
}
40+
41+
int count = 100000;
42+
{
43+
NSMutableArray* objects = [[NSMutableArray alloc] init];
44+
for (int i = 0; i < count; ++i) {
45+
WCTBenchmarkObject* object = [[WCTBenchmarkObject alloc] init];
46+
object.intValue = i;
47+
object.stringValue = [NSString stringWithFormat:@"%d", i];
48+
[objects addObject:object];
49+
}
50+
WCTTable* table = [database getTableOfName:tableName
51+
withClass:WCTBenchmarkObject.class];
52+
WCTBenchmarkStaticstic* staticstic = [[WCTBenchmarkStaticstic alloc] init];
53+
[staticstic start];
54+
BOOL ret = [table insertObjects:objects];
55+
[staticstic stop];
56+
assert(ret);
57+
NSLog(@"Insert %d objects cost %f ms", count, staticstic.getElapseTimes[0].doubleValue);
58+
}
59+
60+
{
61+
WCTTable* table = [database getTableOfName:tableName
62+
withClass:WCTBenchmarkObject.class];
63+
WCTBenchmarkStaticstic* staticstic = [[WCTBenchmarkStaticstic alloc] init];
64+
[staticstic start];
65+
NSArray* objects = [table getAllObjects];
66+
[staticstic stop];
67+
NSLog(@"Select %lu objects cost %f ms", objects.count, staticstic.getElapseTimes[0].doubleValue);
68+
}
69+
}

Apple/WCDB-Info.plist

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>FMWK</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleVersion</key>
20+
<string>$(CURRENT_PROJECT_VERSION)</string>
21+
<key>NSHumanReadableCopyright</key>
22+
<string>Copyright © 2017年 Tencent. All rights reserved.</string>
23+
<key>NSPrincipalClass</key>
24+
<string></string>
25+
</dict>
26+
</plist>

0 commit comments

Comments
 (0)