System.nanoTime() 활용

long start=System.nanoTime();

...
연산
...

long end=System.nanoTime();

double elapsed=(end-start)/1000000.0;

위경도 JAVA TEST

4710.8095
@Override
    public LocationResponseDTO testJavaLocation(LocationRequestDTO locationRequestDTO) {

        long start=System.nanoTime();

        List<Shop> shopList=shopRepository.findAll();

        double myLat=locationRequestDTO.getLatitude();
        double myLng=locationRequestDTO.getLongitude();

        List<ShopResponseDTO> shopDTO=new ArrayList<>();
        for(Shop shop:shopList){

            double shopLat=shop.getLatitude();
            double shopLng=shop.getLongitude();

            double theta = myLng - shopLng;
            double dist = Math.sin((myLat * Math.PI/180.0))* Math.sin((shopLat * Math.PI/180.0))
                    + Math.cos((myLat * Math.PI/180.0))*Math.cos((shopLat * Math.PI/180.0))*Math.cos((theta * Math.PI/180.0));
            dist = Math.acos(dist);
            dist = (dist * 180 / Math.PI);
            dist = dist * 60*1.1515*1609.344;

            shopDTO.add(
                    ShopResponseDTO.builder()
                            .shopName(shop.getName())
                            .address(shop.getAddress())
                            .latitude(shop.getLatitude())
                            .longitude(shop.getLongitude())
                            .distance(dist)
                            .build()
            );
        }
        Collections.sort(shopDTO);

        long end=System.nanoTime();

        double time=(end-start)/1000000.0;

        LocationResponseDTO dto=LocationResponseDTO.builder()
                .shop(shopDTO)
                .time(time)
                .build();

        return dto;
    }

Untitled

RDB 위경도 테스트

Mysql 좌표 거리계산, JPA, nativeQuery 를 이용한 거리계산

Redis 위경도 테스트

Redis Geospatial 데이터 타입의 GeoSearch를 쓰겠습니다

redis geosearch

GeoOperations (Spring Data Redis 3.1.4 API)