Skip to content

Commit 11b5569

Browse files
committed
Initial commit with class generation
1 parent b3406e3 commit 11b5569

File tree

7 files changed

+2497
-3
lines changed

7 files changed

+2497
-3
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2022 Realm Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.realm.kotlin.benchmarks.android
17+
18+
import androidx.benchmark.junit4.BenchmarkRule
19+
import androidx.benchmark.junit4.measureRepeated
20+
import io.realm.generated.tenStringObjectClasses
21+
import io.realm.kotlin.Realm
22+
import io.realm.kotlin.RealmConfiguration
23+
import io.realm.kotlin.benchmarks.SchemaSize
24+
import io.realm.kotlin.types.RealmObject
25+
import org.junit.After
26+
import org.junit.Before
27+
import org.junit.Rule
28+
import org.junit.Test
29+
import org.junit.runner.RunWith
30+
import org.junit.runners.Parameterized
31+
import kotlin.reflect.KClass
32+
33+
@RunWith(Parameterized::class)
34+
class OpenRealmTestsGenerated(private val schemaSize: Int) {
35+
36+
companion object {
37+
@JvmStatic
38+
@Parameterized.Parameters(name = "schema-size-{0}")
39+
fun initParameters(): Collection<Int> {
40+
return setOf(1, 10, 100)
41+
}
42+
}
43+
44+
@get:Rule
45+
val benchmarkRule = BenchmarkRule()
46+
47+
private lateinit var config: RealmConfiguration
48+
private var realm: Realm? = null
49+
50+
@Before
51+
fun setUp() {
52+
val schema: Set<KClass<out RealmObject>> = tenStringObjectClasses.subList(0, schemaSize).toSet()
53+
config = RealmConfiguration.Builder(schema)
54+
.directory("./build/benchmark-realms")
55+
.build()
56+
}
57+
58+
@After
59+
fun tearDown() {
60+
realm?.let {
61+
Realm.deleteRealm(config)
62+
}
63+
}
64+
65+
@Test()
66+
fun openRealm() {
67+
benchmarkRule.measureRepeated {
68+
realm = Realm.open(config)
69+
runWithTimingDisabled {
70+
realm!!.close()
71+
}
72+
}
73+
}
74+
}

benchmarks/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ buildscript {
1212
}
1313
gradlePluginPortal()
1414
google()
15+
mavenLocal()
1516
mavenCentral()
1617
}
1718
dependencies {
@@ -28,6 +29,7 @@ allprojects {
2829
maven("file://${rootProject.rootDir.absolutePath}/../packages/build/m2-buildrepo")
2930
}
3031
google()
32+
mavenLocal()
3133
mavenCentral()
3234
}
3335

benchmarks/settings.gradle.kts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
// For CI buils, the packages are expected to have
1919
// been built and deployed to a local filesystem
2020
// maven repo.
21-
if (System.getenv("JENKINS_HOME") == null) {
22-
includeBuild("../packages")
23-
}
21+
//if (System.getenv("JENKINS_HOME") == null) {
22+
// includeBuild("../packages")
23+
//}
2424

2525
pluginManagement {
2626
repositories {
2727
google()
2828
gradlePluginPortal()
29+
mavenLocal()
2930
mavenCentral()
3031
}
3132
}

benchmarks/shared/build.gradle.kts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import io.realm.ClassGeneratorSpec
2+
import io.realm.generate
3+
14
plugins {
25
kotlin("multiplatform")
36
// kotlin("native.cocoapods")
@@ -57,6 +60,26 @@ kotlin {
5760
}
5861
}
5962

63+
abstract class ClassGenerator : DefaultTask() {
64+
@TaskAction
65+
fun generate() {
66+
val output = project.file("./src/commonMain/kotlin/")
67+
68+
// Clear out any previous contents
69+
project.file("./src/commonMain/kotlin/io/realm/generated").deleteRecursively()
70+
71+
ClassGeneratorSpec(
72+
classCount = 100,
73+
packageName = "io.realm.generated",
74+
className = "TenStringObject",
75+
stringFieldCount = 10
76+
).generate(output)
77+
}
78+
}
79+
80+
// Create a task using the task type
81+
tasks.register<ClassGenerator>("classGen")
82+
6083
android {
6184
compileSdk = Versions.Android.compileSdkVersion
6285
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")

0 commit comments

Comments
 (0)