package com.db.service.framemark.bean;

import com.db.service.model.TTest;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.converter.ConverterFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import org.junit.Test;
import org.springframework.beans.BeanUtils;

/**
 * @author : liukx
 * @create : 2018/9/19 16:26
 * @email : liukx@elab-plus.com
 */
public class BeanCreateTest {

    private MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();


    @Test
    public void createTest() {
        TTest test = new TTest();

        ConverterFactory converterFactory = mapperFactory.getConverterFactory();
        MapperFacade mapperFacade = mapperFactory.getMapperFacade();

        int count = 1200000;
        cloneOrika(test, mapperFacade, count);

        System.out.println("----------------");
        cloneReflection(test, count);

    }

    private void cloneOrika(TTest test, MapperFacade mapperFacade, int count) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < count; i++) {
            TTest map = mapperFacade.map(test, TTest.class);
        }
        long time = System.currentTimeMillis() - start;
        System.out.println(time);
    }

    private void cloneReflection(TTest test, int count) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < count; i++) {
            TTest instantiate = BeanUtils.instantiate(TTest.class);
        }
        long time = System.currentTimeMillis() - start;
        System.out.println(time);
    }

}
