codecov[bot]: # [Codecov](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17?src=pr&el=h1) Report
> Merging [#17](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17?src=pr&el=desc) into [master](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/commit/e98f169203de3478a4999376aac03323c5f54786&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17/graphs/tree.svg?width=650&height=150&src=pr&token=0d9Lc3Cmzr)](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #17      +/-   ##
==========================================
- Coverage   98.63%   98.59%   -0.04%     
==========================================
  Files           4        4              
  Lines         219      213       -6     
  Branches       32       32              
==========================================
- Hits          216      210       -6     
  Misses          1        1              
  Partials        2        2              
```


| [Impacted Files](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [easy\_profile/profiler.py](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17/diff?src=pr&el=tree#diff-ZWFzeV9wcm9maWxlL3Byb2ZpbGVyLnB5) | `97.93% <100.00%> (-0.11%)` | :arrow_down: |
| [easy\_profile/reporters.py](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17/diff?src=pr&el=tree#diff-ZWFzeV9wcm9maWxlL3JlcG9ydGVycy5weQ==) | `100.00% <0.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17?src=pr&el=footer). Last update [e98f169...e6b9ff4](https://codecov.io/gh/dmvass/sqlalchemy-easy-profile/pull/17?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 58e2c0a..d446327 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 
 ## [Unreleased]
 
+## [1.1.1] - 2020-07-26
+- Fixed deprecated time.clock [issue-16]
+
 ## [1.1.0] - 2020-06-29
 - Removed support of python 2.7, 3.5
 - Updated documentation
diff --git a/easy_profile/profiler.py b/easy_profile/profiler.py
index bfefff7..bc91152 100644
--- a/easy_profile/profiler.py
+++ b/easy_profile/profiler.py
@@ -3,20 +3,13 @@ import functools
 import inspect
 from queue import Queue
 import re
-import sys
-import time
+from time import perf_counter
 
 from sqlalchemy import event
 from sqlalchemy.engine.base import Engine
 
 from .reporters import StreamReporter
 
-# Optimize timer function for the platform
-if sys.platform == "win32":  # pragma: no cover
-    _timer = time.clock
-else:
-    _timer = time.time
-
 
 SQL_OPERATORS = ["select", "insert", "update", "delete"]
 OPERATOR_REGEX = re.compile("(%s) *." % "|".join(SQL_OPERATORS), re.IGNORECASE)
@@ -177,10 +170,10 @@ class SessionProfiler:
 
     def _before_cursor_execute(self, conn, cursor, statement, parameters,
                                context, executemany):
-        context._query_start_time = _timer()
+        context._query_start_time = perf_counter()
 
     def _after_cursor_execute(self, conn, cursor, statement, parameters,
                               context, executemany):
         self.queries.put(DebugQuery(
-            statement, parameters, context._query_start_time, _timer()
+            statement, parameters, context._query_start_time, perf_counter()
         ))

Does not work on python 3.8
Exception raises when trying to use time.clock on profiler.py.

timer.clock was deprecated since Python 3.3 and removed in 3.8.

From Python DOCs:

Deprecated since version 3.3, will be removed in version 3.8: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.


diff --git a/tests/test_profiler.py b/tests/test_profiler.py
index 1a64f49..eee3a40 100644
--- a/tests/test_profiler.py
+++ b/tests/test_profiler.py
@@ -142,9 +142,9 @@ class TestSessionProfiler(unittest.TestCase):
         self.assertListEqual(debug_queries, stats["call_stack"])
         self.assertDictEqual(stats["duplicates"], duplicates)
 
-    @mock.patch("easy_profile.profiler._timer")
+    @mock.patch("easy_profile.profiler.perf_counter")
     def test__before_cursor_execute(self, mocked):
-        expected_time = time.time()
+        expected_time = time.perf_counter()
         mocked.return_value = expected_time
         profiler = SessionProfiler()
         context = mock.Mock()
@@ -158,7 +158,7 @@ class TestSessionProfiler(unittest.TestCase):
         )
         self.assertEqual(context._query_start_time, expected_time)
 
-    @mock.patch("easy_profile.profiler._timer")
+    @mock.patch("easy_profile.profiler.perf_counter")
     def test__after_cursor_execute(self, mocked):
         expected_query = debug_queries[0]
         mocked.return_value = expected_query.end_time

pip install -e .[dev]
parse_log_pytest
pytest
pytest
3.7
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///croot/attrs_1668696182826/work
bump2version==1.0.1
bumpversion==0.6.0
cachetools==5.5.2
certifi @ file:///croot/certifi_1671487769961/work/certifi
chardet==5.2.0
colorama==0.4.6
distlib==0.3.9
filelock==3.12.2
flit_core @ file:///opt/conda/conda-bld/flit-core_1644941570762/work/source/flit_core
importlib-metadata==6.7.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
packaging==24.0
platformdirs==4.0.0
pluggy==1.2.0
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyproject-api==1.5.3
pytest==7.1.2
SQLAlchemy==1.3.24
-e git+https://github.com/dmvass/sqlalchemy-easy-profile.git@e98f169203de3478a4999376aac03323c5f54786#egg=sqlalchemy_easy_profile
sqlparse==0.4.4
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work
tox==4.8.0
typing_extensions==4.7.1
virtualenv==20.26.6
zipp @ file:///croot/zipp_1672387121353/work

name: sqlalchemy-easy-profile
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=22.1.0=py37h06a4308_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - flit-core=3.6.0=pyhd3eb1b0_0
  - importlib_metadata=4.11.3=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pytest=7.1.2=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py37h06a4308_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.11.0=py37h06a4308_0
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - bump2version==1.0.1
      - bumpversion==0.6.0
      - cachetools==5.5.2
      - chardet==5.2.0
      - colorama==0.4.6
      - distlib==0.3.9
      - filelock==3.12.2
      - importlib-metadata==6.7.0
      - packaging==24.0
      - platformdirs==4.0.0
      - pluggy==1.2.0
      - pyproject-api==1.5.3
      - sqlalchemy==1.3.24
      - sqlparse==0.4.4
      - tox==4.8.0
      - typing-extensions==4.7.1
      - virtualenv==20.26.6
prefix: /opt/conda/envs/sqlalchemy-easy-profile

tests/test_profiler.py::TestSessionProfiler::test__after_cursor_execute tests/test_profiler.py::TestSessionProfiler::test__before_cursor_execute
tests/test_profiler.py::TestSessionProfiler::test__get_stats tests/test_profiler.py::TestSessionProfiler::test__reset_stats tests/test_profiler.py::TestSessionProfiler::test_begin tests/test_profiler.py::TestSessionProfiler::test_begin_alive tests/test_profiler.py::TestSessionProfiler::test_commit tests/test_profiler.py::TestSessionProfiler::test_commit_alive tests/test_profiler.py::TestSessionProfiler::test_contextmanager_interface tests/test_profiler.py::TestSessionProfiler::test_decorator tests/test_profiler.py::TestSessionProfiler::test_decorator_path tests/test_profiler.py::TestSessionProfiler::test_decorator_path_and_path_callback tests/test_profiler.py::TestSessionProfiler::test_decorator_path_callback tests/test_profiler.py::TestSessionProfiler::test_initialization_custom tests/test_profiler.py::TestSessionProfiler::test_initialization_default tests/test_profiler.py::TestSessionProfiler::test_stats
easy_profile/profiler.py CHANGELOG.md
easy_profile/profiler.py CHANGELOG.md