Skip to content

Commit

Permalink
Add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
elsid authored and thed636 committed Sep 14, 2018
1 parent 7c6e2cd commit d394642
Show file tree
Hide file tree
Showing 13 changed files with 918 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ endif()
if(OZO_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if(OZO_BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
50 changes: 50 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wsign-compare -pedantic -Werror")

execute_process(COMMAND echo "int main() { return 0;}" OUTPUT_FILE test.cpp)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -std=c++17 test.cpp -o a.out RESULT_VARIABLE CPP17_READY_RESULT)
execute_process(COMMAND rm test.cpp OUTPUT_QUIET ERROR_QUIET)
execute_process(COMMAND rm a.out OUTPUT_QUIET ERROR_QUIET)

if ("${CPP17_READY_RESULT}" STREQUAL "0")
set(CPP17_READY 1)
else()
set(CPP17_NOT_READY 1)
endif()

if (CPP17_READY)
message(STATUS "compiler supports -std=c++17")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
else()
message(STATUS "compiler does not support -std=c++17, using -std=c++1z instead")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ignored-optimization-argument")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-string-literal-operator-template")
endif()

find_program(CCACHE_FOUND ccache)

if(CCACHE_FOUND)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif()

find_package(Boost COMPONENTS coroutine context system thread REQUIRED)
include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")

find_package(PostgreSQL)
include_directories(SYSTEM "${PostgreSQL_INCLUDE_DIRS}")

set(LIBRARIES
pthread
${Boost_LIBRARIES}
${PostgreSQL_LIBRARIES}
)

add_executable(ozo_benchmark ozo_benchmark.cpp)
target_link_libraries(ozo_benchmark ${LIBRARIES})

add_executable(ozo_benchmark_performance performance.cpp)
target_link_libraries(ozo_benchmark_performance ${LIBRARIES})
43 changes: 43 additions & 0 deletions benchmarks/aiopg_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

import asyncio
import aiopg
import time
import sys


def main():
loop = asyncio.get_event_loop()
loop.run_until_complete(run())


async def run():
total_rows = [0]
start = time.monotonic()
await asyncio.gather(*[reuse_connection(total_rows) for _ in range(CONNECTIONS)])
finish = time.monotonic()
print('read %s rows, %.3f row/sec' % (total_rows[0], total_rows[0] / (finish - start)))


async def reuse_connection(total_rows):
conn = await aiopg.connect(sys.argv[1])
async with conn.cursor() as cur:
while total_rows[0] < 10000000:
await cur.execute(QUERY, parameters=(-1, True))
values = []
async for row in cur:
values.append(row)
total_rows[0] += len(values)
await conn.close()


CONNECTIONS = 8
QUERY = '''
SELECT typname, typnamespace, typowner, typlen, typbyval, typcategory,
typispreferred, typisdefined, typdelim, typrelid, typelem, typarray
FROM pg_type
WHERE typtypmod = %s AND typisdefined = %s
'''

if __name__ == '__main__':
main()
39 changes: 39 additions & 0 deletions benchmarks/asyncpg_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3

import asyncio
import asyncpg
import time
import sys


def main():
loop = asyncio.get_event_loop()
loop.run_until_complete(run())


async def run():
total_rows = [0]
start = time.monotonic()
await asyncio.gather(*[reuse_connection(total_rows) for _ in range(CONNECTIONS)])
finish = time.monotonic()
print('read %s rows, %.3f row/sec' % (total_rows[0], total_rows[0] / (finish - start)))


async def reuse_connection(total_rows):
conn = await asyncpg.connect(sys.argv[1])
while total_rows[0] < 10000000:
values = await conn.fetch(QUERY, -1, True)
total_rows[0] += len(values)
await conn.close()


CONNECTIONS = 8
QUERY = '''
SELECT typname, typnamespace, typowner, typlen, typbyval, typcategory,
typispreferred, typisdefined, typdelim, typrelid, typelem, typarray
FROM pg_type
WHERE typtypmod = $1 AND typisdefined = $2
'''

if __name__ == '__main__':
main()
Loading

0 comments on commit d394642

Please sign in to comment.