Re: Debugging reason for python running unreasonably slow when adding numbers
Il giorno lunedì 20 marzo 2023 alle 19:10:26 UTC+1 Thomas Passin ha scritto: > On 3/20/2023 11:21 AM, Edmondo Giovannozzi wrote: > > > >>> def sum1(): > >>> s = 0 > >>> for i in range(100): > >>> s += i > >>> return s > >>> > >>> def sum2(): > >>> return sum(range(100)) > >> Here you already have the numbers you want to add. > > > > Actually using numpy you'll be much faster in this case: > > > > § import numpy as np > > § def sum3(): > > § return np.arange(1_000_000, dtype=np.int64).sum() > > > > On my computer sum1 takes 44 ms, while the numpy version just 2.6 ms > > One problem is that sum2 gives the wrong result. This is why I used > > np.arange with dtype=np.int64. > On my computer they all give the same result. > > Python 3.10.9, PyQt version 6.4.1 > Windows 10 AMD64 (build 10.0.19044) SP0 > Processor: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz, 1690 Mhz, 4 > Core(s), 8 Logical Processor(s) > > sum2 evidently doesn't uses the python "big integers" e restrict the result > > to 32 bits. > What about your system? Let's see if we can figure the reason for the > difference. I'm using winpython on Windows 11 and the python version is, well, 3.11: But it is my fault, sorry, I realised now that ipython is importing numpy namespace and the numpy sum function is overwriting the intrinsic sum. The intrinsic sum is behaving correctly and is faster when used in sum(range(1_000_000)) then the numpy version. -- https://mail.python.org/mailman/listinfo/python-list
[Python-announce] SCons 4.5.2 Released
A new SCons release, 4.5.2, is now available on the SCons download page: https://scons.org/pages/download.html Here is a summary of the changes since 4.5.1: FIXES - - Fix a problem (#4321) in 4.5.0/4.5.1 where ParseConfig could cause an exception in MergeFlags when the result would be to add preprocessor defines to existing CPPDEFINES. The following code illustrates the circumstances that could trigger this: env=Environment(CPPDEFINES=['a']) env.Append(CPPDEFINES=['b']) env.MergeFlags({'CPPDEFINES': 'c'}) PACKAGING - - Remove the redundant `wheel` dependency from `pyproject.toml`, as it is added automatically by the setuptools PEP517 backend. Thanks to the following contributors listed below for their contributions to this release. == .. code-block:: text git shortlog --no-merges -ns 4.5.1..HEAD 3 Mats Wichmann 2 William Deegan 1 Michał Górny ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com
[Python-announce] unittest_expander 0.4.4 released
Dear Pythonistas, I am pleased to announce the release of unittest_expander 0.4.4. The changelog is available at: https://unittest-expander.readthedocs.io/en/stable/changes.html *** *unittest_expander* is a MIT-licensed Python library that provides flexible and easy-to-use tools to parameterize your unit tests, especially those based on `unittest.TestCase`. The library is compatible with Python 3.11, 3.10, 3.9, 3.8, 3.7, 3.6 and 2.7, and does not depend on any external packages (uses only the Python standard library). Simple usage example: ``` import unittest from unittest_expander import expand, foreach, param @expand class TestSomething(unittest.TestCase): @foreach( 'Foo', ('Foo', 43), param('Foo', spam=44), param(foo='Bar', spam=45).label('with bar'), empty=param(foo='', spam=46), ) def test_it(self, foo, spam=42, label=None): assert foo in ('Foo', 'Bar', '') assert 42 <= spam <= 46 if label == 'with bar': assert foo == 'Bar' and spam == 45 if label == 'empty': assert foo == '' and spam == 46 ``` This is only a fraction of the possibilities the unittest_expander library provides. Homepage: https://github.com/zuo/unittest_expander PyPI: https://pypi.org/project/unittest-expander/ Documentation: https://unittest-expander.readthedocs.io/en/stable/ Cheers, Jan Kaliszewski (zuo) z...@kaliszewski.net ___ Python-announce-list mailing list -- python-announce-list@python.org To unsubscribe send an email to python-announce-list-le...@python.org https://mail.python.org/mailman3/lists/python-announce-list.python.org/ Member address: arch...@mail-archive.com