Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
John-He-928 committed May 19, 2017
0 parents commit b99e82b
Show file tree
Hide file tree
Showing 872 changed files with 487,537 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .gitignore
@@ -0,0 +1,19 @@
# Visual Studio Code
.vscode

# Android Studio, Gradle
*.iml
.gradle
.idea
.settings
.project
.classpath
.DS_Store
.externalNativeBuild

# Xcode
*.pbxuser
xcuserdata
xcuserdata/*
*.xcworkspace/*
*.xcworkspace
6 changes: 6 additions & 0 deletions .gitmodules
@@ -0,0 +1,6 @@
[submodule "sqlcipher"]
path = sqlcipher
url = https://github.com/Tencent/sqlcipher.git
[submodule "openssl"]
path = openssl
url = https://github.com/openssl/openssl.git
32 changes: 32 additions & 0 deletions Apple/Benchmark/WCTBenchmarkObject.h
@@ -0,0 +1,32 @@
/*
* Tencent is pleased to support the open source community by making
* WCDB available.
*
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import <WCDB/WCDB.h>

@interface WCTBenchmarkObject : NSObject<WCTTableCoding>

@property int intValue;
@property(retain) NSString* stringValue;

WCDB_PROPERTY(intValue)
WCDB_PROPERTY(stringValue)

@end
31 changes: 31 additions & 0 deletions Apple/Benchmark/WCTBenchmarkObject.mm
@@ -0,0 +1,31 @@
/*
* Tencent is pleased to support the open source community by making
* WCDB available.
*
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "WCTBenchmarkObject.h"

@implementation WCTBenchmarkObject

WCDB_IMPLEMENTATION(WCTBenchmarkObject)
WCDB_SYNTHESIZE(WCTBenchmarkObject, intValue)
WCDB_SYNTHESIZE(WCTBenchmarkObject, stringValue)

WCDB_PRIMARY(WCTBenchmarkObject, intValue)

@end
32 changes: 32 additions & 0 deletions Apple/Benchmark/WCTBenchmarkStaticstic.h
@@ -0,0 +1,32 @@
/*
* Tencent is pleased to support the open source community by making
* WCDB available.
*
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

@interface WCTBenchmarkStaticstic : NSObject

- (void)start;
- (void)tick;
- (void)stop;

- (NSArray<NSNumber*>*)getElapseTimes;
- (void)report;

@end
79 changes: 79 additions & 0 deletions Apple/Benchmark/WCTBenchmarkStaticstic.mm
@@ -0,0 +1,79 @@
/*
* Tencent is pleased to support the open source community by making
* WCDB available.
*
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "WCTBenchmarkStaticstic.h"
#import <mach/mach_time.h>

@implementation WCTBenchmarkStaticstic {
NSMutableArray<NSNumber*>* _ticks;
}

- (instancetype)init
{
if (self = [super init]) {
_ticks = [[NSMutableArray alloc] init];
}
return self;
}

- (void)start
{
[self tick];
}

- (void)tick
{
NSNumber* time = [NSNumber numberWithLongLong:mach_absolute_time()];
[_ticks addObject:time];
}

- (void)stop
{
[self tick];
}

- (void)report
{
for (NSNumber* elapse in [self getElapseTimes]) {
NSLog(@"Tick cost : %f ms", elapse.doubleValue);
}
}

- (NSArray<NSNumber*>*)getElapseTimes
{
NSMutableArray<NSNumber*>* elapseTimes = [[NSMutableArray alloc] init];
mach_timebase_info_data_t info;
mach_timebase_info(&info);

uint64_t lastTick = 0;
for (NSUInteger i = 0; i < _ticks.count; ++i) {
uint64_t currentTick = _ticks[i].longLongValue;
if (i>0) {
uint64_t elapse = currentTick-lastTick;
double ns = (double)elapse * (double)info.numer / (double)info.denom;
double ms = ns/1000/1000;
[elapseTimes addObject:[NSNumber numberWithDouble:ms]];
}
lastTick = currentTick;
}
return elapseTimes;
}

@end
30 changes: 30 additions & 0 deletions Apple/Benchmark/benchmark_main.mm
@@ -0,0 +1,30 @@
/*
* Tencent is pleased to support the open source community by making
* WCDB available.
*
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import "benchmark_normal.h"
int main(int argc, const char * argv[]) {
#warning TODO Perfect benchmark works
NSString* machPath = [NSString stringWithUTF8String:argv[0]];
NSString* baseDirectory = [[machPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"SampleDB"];
NSLog(@"Base Directory: %@", baseDirectory);
benchmark_normal(baseDirectory);
return 0;
}
23 changes: 23 additions & 0 deletions Apple/Benchmark/benchmark_normal.h
@@ -0,0 +1,23 @@
/*
* Tencent is pleased to support the open source community by making
* WCDB available.
*
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>

void benchmark_normal(NSString* baseDirectory);
69 changes: 69 additions & 0 deletions Apple/Benchmark/benchmark_normal.mm
@@ -0,0 +1,69 @@
/*
* Tencent is pleased to support the open source community by making
* WCDB available.
*
* Copyright (C) 2017 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "benchmark_normal.h"
#import "WCTBenchmarkStaticstic.h"
#import "WCTBenchmarkObject.h"

void benchmark_normal(NSString* baseDirectory)
{
NSString* className = NSStringFromClass(WCTBenchmarkObject.class);
NSString* path = [baseDirectory stringByAppendingPathComponent:className];
NSString* tableName = className;
WCTDataBase* database = [[WCTDataBase alloc] initWithPath:path];
[database close:^{
[database removeFilesWithError:nil];
}];

{
BOOL ret = [database createTableAndIndexesOfName:tableName
withClass:WCTBenchmarkObject.class];
assert(ret);
}

int count = 100000;
{
NSMutableArray* objects = [[NSMutableArray alloc] init];
for (int i = 0; i < count; ++i) {
WCTBenchmarkObject* object = [[WCTBenchmarkObject alloc] init];
object.intValue = i;
object.stringValue = [NSString stringWithFormat:@"%d", i];
[objects addObject:object];
}
WCTTable* table = [database getTableOfName:tableName
withClass:WCTBenchmarkObject.class];
WCTBenchmarkStaticstic* staticstic = [[WCTBenchmarkStaticstic alloc] init];
[staticstic start];
BOOL ret = [table insertObjects:objects];
[staticstic stop];
assert(ret);
NSLog(@"Insert %d objects cost %f ms", count, staticstic.getElapseTimes[0].doubleValue);
}

{
WCTTable* table = [database getTableOfName:tableName
withClass:WCTBenchmarkObject.class];
WCTBenchmarkStaticstic* staticstic = [[WCTBenchmarkStaticstic alloc] init];
[staticstic start];
NSArray* objects = [table getAllObjects];
[staticstic stop];
NSLog(@"Select %lu objects cost %f ms", objects.count, staticstic.getElapseTimes[0].doubleValue);
}
}
26 changes: 26 additions & 0 deletions Apple/WCDB-Info.plist
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017年 Tencent. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

0 comments on commit b99e82b

Please sign in to comment.