How do I “multi-process” the itertools product module?

后端 未结 2 997
醉酒成梦
醉酒成梦 2020-12-03 16:07

So I tried I tried calculating millions and millions of different combinations of the below string but I was only calculating roughly 1,750 combinations a second which isn\'

2条回答
  •  忘掉有多难
    2020-12-03 16:50

    Are you sure you're only getting 1750 combinations per second? I'm getting about 10 million.

    def test(n):
        start = time.time()
        count = 0
        for chars in product("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ12234567890!@#$%^&*?,()-=+[]/;", repeat = 4):
    
            count += 1
            if count == n: break
        return time.time() - start    
    
    >>> test(10000)
    0.03300023078918457
    >>> test(1000000)
    0.15799999237060547
    >>> test(10000000)
    1.0469999313354492
    

    I don't think my computer is that much faster than yours.

    note: I posted this as an answer because I wanted to show code. It's really more of a comment. So please, no upvotes or downvotes.

提交回复
热议问题