Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: spring-projects/spring-data-mongodb
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: automation-engineering/spring-data-mongodb
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: perf
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on May 22, 2015

  1. Hacking.

    odrotbohm committed May 22, 2015
    Copy the full SHA
    f864024 View commit details

Commits on May 25, 2015

  1. Upgraded to JMH 1.9.3.

    odrotbohm committed May 25, 2015
    Copy the full SHA
    ec8565b View commit details
101 changes: 101 additions & 0 deletions spring-data-mongodb-benchmarks/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-mongodb-benchmarks</artifactId>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.7.0.BUILD-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<name>Spring Data MongoDB - Benchmarks</name>

<dependencies>

<!-- Spring Data -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.14.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>

</dependencies>

<properties>
<jmh.version>1.9.3</jmh.version>
<javac.target>1.6</javac.target>
<uberjar.name>benchmarks</uberjar.name>
<bundlor.enabled>false</bundlor.enabled>
</properties>

<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${uberjar.name}</finalName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<!-- Shading signed JARs will fail without this. http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.springframework.data.mongodb.benchmarks;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class Address {

private String zipCode, city;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package org.springframework.data.mongodb.benchmarks;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;

/**
* @author Oliver Gierke
*/
@Getter
@RequiredArgsConstructor
public class Customer {

private @Id ObjectId id;
private final String firstname, lastname;
private final Address address;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright (c) 2014, Oracle America, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Oracle nor the names of its contributors may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.springframework.data.mongodb.benchmarks;

import java.net.UnknownHostException;
import java.util.Collections;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.springframework.data.convert.EntityInstantiator;
import org.springframework.data.convert.EntityInstantiators;
import org.springframework.data.mapping.PreferredConstructor.Parameter;
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.core.convert.DbRefResolver;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;

@State(Scope.Benchmark)
public class MyBenchmark {

private final MongoMappingContext mappingContext;
private final MappingMongoConverter converter;
private final DBObject plainSource, sourceWithAddress;
private final Customer withAddress;

public MyBenchmark() {

MongoClient mongo;

try {
mongo = new MongoClient();
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}

this.mappingContext = new MongoMappingContext();
this.mappingContext.setInitialEntitySet(Collections.singleton(Customer.class));
this.mappingContext.afterPropertiesSet();

DbRefResolver dbRefResolver = new DefaultDbRefResolver(new SimpleMongoDbFactory(mongo, "benchmark"));

this.converter = new MappingMongoConverter(dbRefResolver, mappingContext);
this.plainSource = new BasicDBObject("firstname", "Dave").append("lastname", "Matthews");

DBObject address = new BasicDBObject("zipCode", "ABCDE").append("city", "Some Place");

this.sourceWithAddress = new BasicDBObject("firstname", "Dave").//
append("lastname", "Matthews").//
append("address", address);

this.withAddress = new Customer("Dave", "Matthews", new Address("zipCode", "City"));
}

@Benchmark
public void readPlainSource() {
converter.read(Customer.class, plainSource);
}

@Benchmark
public void readSourceWithAddress() {
converter.read(Customer.class, sourceWithAddress);
}

@Benchmark
public void writeSourceWithAddress() {
converter.write(withAddress, new BasicDBObject());
}

public void foo() {

BasicMongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(Customer.class);

EntityInstantiators instantiators = new EntityInstantiators();
EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity);

instantiator.createInstance(entity, new ParameterValueProvider<MongoPersistentProperty>() {

@Override
public <T> T getParameterValue(Parameter<T, MongoPersistentProperty> parameter) {
return null;
}
});
}

@Benchmark
public void testMethod() {

DBObject addressSource = (DBObject) sourceWithAddress.get("address");
Address address = new Address(addressSource.get("zipCode").toString(), addressSource.get("city").toString());

foo(new Customer(sourceWithAddress.get("firstname").toString(), sourceWithAddress.get("lastname").toString(),
address));
}

private void foo(Customer customer) {}

public static void main(String[] args) throws RunnerException {

Options opt = new OptionsBuilder().//
include(MyBenchmark.class.getSimpleName()).//
forks(1).//
build();

new Runner(opt).run();
}
}