Telegram Group & Telegram Channel
آشنایی با تابع ()compile - مقدمه ای بر JiT
اگر از کاربران قدیمی پایتون باشید، یکی از مسائلی که همیشه به آن اشاره می شد کندی برنامه های پایتون به دلیل استفاده از مفسر بود. اگر چه استفاده از مفسر برای کارهای علم داده که عموما با آزمون و خطا به حل مسئله می پردازیم خیلی هم بد نبود و حتی سرعت توسعه نرم افزار را بالا می برد اما برای توسعه برنامه های تجاری راهکار بهینه ای نبود. خوشبختانه در نسخه های اخیر پایتون، JiT یا همان اجرای در لحظه (Just in Time) وارد ادبیات پایتون شده است.
یکی از توابع معرفی شده در این خصوص تابع ()compile است. این تابع به نحو قابل قبولی باعث بهبود عملکرد برنامه می شود، چرا که بایت‌کد که توسط ()compile تولید می‌شود، سریعتر از سورس برنامه اصلی نوشته شده به زبان پایتون اجرا می‌شود زیرا قبلاً به یک فرم قابل اجرا توسط مفسر تبدیل شده است.

یک مثال
#code by @python4finance
source_code = """
a=5
for i in range(a):
print(i)
if i==3:
print("*")
"""
compiled_code = compile(source_code, filename="<string>", mode="exec")
exec(compiled_code)


#پایتون_پیشرفته
#JiT
#compile

پایتون برای مالی
🆔 www.tg-me.com/ms/Python4Finance/com.python4finance
🆔 ble.ir/ms/Python4Finance/com.python4finance



tg-me.com/python4finance/1081
Create:
Last Update:

آشنایی با تابع ()compile - مقدمه ای بر JiT
اگر از کاربران قدیمی پایتون باشید، یکی از مسائلی که همیشه به آن اشاره می شد کندی برنامه های پایتون به دلیل استفاده از مفسر بود. اگر چه استفاده از مفسر برای کارهای علم داده که عموما با آزمون و خطا به حل مسئله می پردازیم خیلی هم بد نبود و حتی سرعت توسعه نرم افزار را بالا می برد اما برای توسعه برنامه های تجاری راهکار بهینه ای نبود. خوشبختانه در نسخه های اخیر پایتون، JiT یا همان اجرای در لحظه (Just in Time) وارد ادبیات پایتون شده است.
یکی از توابع معرفی شده در این خصوص تابع ()compile است. این تابع به نحو قابل قبولی باعث بهبود عملکرد برنامه می شود، چرا که بایت‌کد که توسط ()compile تولید می‌شود، سریعتر از سورس برنامه اصلی نوشته شده به زبان پایتون اجرا می‌شود زیرا قبلاً به یک فرم قابل اجرا توسط مفسر تبدیل شده است.

یک مثال

#code by @python4finance
source_code = """
a=5
for i in range(a):
print(i)
if i==3:
print("*")
"""
compiled_code = compile(source_code, filename="<string>", mode="exec")
exec(compiled_code)


#پایتون_پیشرفته
#JiT
#compile

پایتون برای مالی
🆔 www.tg-me.com/ms/Python4Finance/com.python4finance
🆔 ble.ir/ms/Python4Finance/com.python4finance

BY Python4Finance


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python4finance/1081

View MORE
Open in Telegram


Python4Finance Telegram | DID YOU KNOW?

Date: |

The Singapore stock market has alternated between positive and negative finishes through the last five trading days since the end of the two-day winning streak in which it had added more than a dozen points or 0.4 percent. The Straits Times Index now sits just above the 3,060-point plateau and it's likely to see a narrow trading range on Monday.

Pinterest (PINS) Stock Sinks As Market Gains

Pinterest (PINS) closed at $71.75 in the latest trading session, marking a -0.18% move from the prior day. This change lagged the S&P 500's daily gain of 0.1%. Meanwhile, the Dow gained 0.9%, and the Nasdaq, a tech-heavy index, lost 0.59%. Heading into today, shares of the digital pinboard and shopping tool company had lost 17.41% over the past month, lagging the Computer and Technology sector's loss of 5.38% and the S&P 500's gain of 0.71% in that time. Investors will be hoping for strength from PINS as it approaches its next earnings release. The company is expected to report EPS of $0.07, up 170% from the prior-year quarter. Our most recent consensus estimate is calling for quarterly revenue of $467.87 million, up 72.05% from the year-ago period.

Python4Finance from ms


Telegram Python4Finance
FROM USA