Skip to content

Instantly share code, notes, and snippets.

@scivision
Created February 12, 2024 16:37
Show Gist options
  • Save scivision/c7377450e3038c3808138189c57a0478 to your computer and use it in GitHub Desktop.
Save scivision/c7377450e3038c3808138189c57a0478 to your computer and use it in GitHub Desktop.
benchmark CMake ExternalProject/FetchContent URL vs GIT_REPOSITORY
# benchmark download of URL vs. Git
# benchmark with CMake 3.28.2 on Windows with gigabit internet connection.
#
# Python 3.12.2 source
# 7 seconds: URL archive 27583112 bytes
# 84 seconds GIT_SHALLOW=true
# 132 seconds GIT_SHALLOW=false
#
# CMake 3.28.3 source:
# 15 seconds: URL archive 11063505 bytes
# 44 seconds: GIT_SHALLOW=true
# 68 seconds: GIT_SHALLOW=false
cmake_minimum_required(VERSION 3.22...3.29)
project(dl LANGUAGES NONE)
option(CMAKE_TLS_VERIFY "Enable TLS verification" ON)
include(FetchContent)
message(STATUS "CMake ${CMAKE_VERSION}")
set(python_version 3.12.2)
set(url https://github.com/python/cpython/archive/refs/tags/v${python_version}.tar.gz)
set(git https://github.com/python/cpython.git)
set(tag v${python_version})
set(cmake_version 3.28.3)
set(url https://github.com/Kitware/CMake/archive/refs/tags/v${cmake_version}.tar.gz)
set(git https://github.com/Kitware/CMake.git)
set(tag v${cmake_version})
set(FETCHCONTENT_QUIET OFF)
set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
function(fetcher name url tag shallow)
string(TIMESTAMP t0 "%s")
if(url MATCHES ".git$")
FetchContent_Declare(${name}
GIT_REPOSITORY "${url}"
GIT_TAG "${tag}"
GIT_SHALLOW "${shallow}"
)
else()
FetchContent_Declare(${name} URL "${url}")
endif()
if(NOT ${name}_POPULATED)
FetchContent_Populate(${name})
endif()
string(TIMESTAMP t1 "%s")
math(EXPR t_url "${t1} - ${t0}")
message(STATUS "${name}: ${t_url} seconds")
if(NOT url MATCHES ".git$")
cmake_path(GET url FILENAME archive_name)
set(archive ${${name}_SOURCE_DIR}/../${name}-subbuild/${name}-populate-prefix/src/${archive_name})
if(EXISTS ${archive})
file(SIZE ${archive} asize)
message(STATUS "${name}: ${archive} size [bytes] ${asize}")
endif()
endif()
endfunction()
fetcher("url_archive" "${url}" "" "")
fetcher("git_shallow" "${git}" "${tag}" "true")
fetcher("git_deep" "${git}" "${tag}" "false")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment