source 는 Github 에 있습니다.
SimpleJpaRepository.java
@Transactional
@Override
public <S extends T> S save(S entity) {
if (entityInformation.isNew(entity)) {
em.persist(entity);
return entity;
} else {
return em.merge(entity);
}
}
@Transactional
@Override
public <S extends T> List<S> saveAll(Iterable<S> entities) {
Assert.notNull(entities, "Entities must not be null!");
List<S> result = new ArrayList<S>();
for (S entity : entities) {
result.add(save(entity));
}
return result;
}
@RunWith(SpringRunner.class)
@DataJpaTest
public class MemberRepositoryTest {
@Autowired
private MemberRepository memberRepository;
private final int SIZE = 100;
@Test
public void save_대량_성능_테스트() throws Exception {
long start = System.currentTimeMillis();
for (int i = 0 ; i < SIZE ; i++) {
Member member = Member.builder()
.age(10)
.name("test")
.telNo("123")
.build();
memberRepository.save(member);
}
System.out.println("elapsed time : " + (System.currentTimeMillis() - start));
}
@Test
public void saveAll_대량_성능_테스트() throws Exception {
long start = System.currentTimeMillis();
List<Member> members = new ArrayList<>();
for (int i = 0 ; i < SIZE ; i++) {
Member member = Member.builder()
.age(10)
.name("test")
.telNo("123")
.build();
members.add(member);
}
memberRepository.saveAll(members);
System.out.println("elapsed time : " + (System.currentTimeMillis() - start));
}
}