Pypy3 slower in generating list of dictionaries

Viewed 57

Is there a way to speed up list comprehension (list of dictionaries) with pypy3? Normally pypy3 is much faster than cpython in normal calculation/logic. It is slightly faster in generating a normal list (create_data1), but generating a list of dictionaries (create_data2), it seems to be 3x slower than regular python3

import pandas as pd
import datetime

NUMS = 1000000

def create_data1():
    start = datetime.datetime.now()
    data = [x for x in range(NUMS)]
    print("create_data1: {}".format(datetime.datetime.now() - start))
    return data


def create_data2():
    start = datetime.datetime.now()
    data = [{'a': x, 'b': x, 'c': x} for x in range(NUMS)]
    print("create_data2: {}".format(datetime.datetime.now() - start))
    return data

_ = create_data1()
_ = create_data2()

results with python3.8.2:

create_data1: 0:00:00.037305
create_data2: 0:00:00.228406

results with pypy3 7.3.2 (python 3.6.9):

create_data1: 0:00:00.030844
create_data2: 0:00:00.620640
0 Answers
Related