numba加速python学习与尝试
学习:人工智能-机器学习-深度学习概念的区别

使用numba的姿势不正确反而导致性能下降

妙音 posted @ 2019年1月20日 09:24 in tensorflow with tags python 性能 , 2873 阅读
numba能够极大的提高python在计算方面的性能。是不是所有的python代码上,都可以加上numba.jit装饰器?答案是否定的。
 
 
 

示例

 

环境

 
python3.6
fedora
pymysql
 

示例

 
很常见的例子,从数据库从查询一千条数据,再进行简单的格式转换。
 
#coding=utf-8
import time
from numba import jit

import pymysql
conn = pymysql.connect("192.168.10.125", "username", "password", "db_name")

#@jit   #位置1
def test_for():
    c =conn.cursor()
    c.execute("select * from user limit 1000")

    start = time.time()
    for a in c.fetchall():
        to_dict(a, c.description)
    end = time.time()
    print("cost_seconds:", end-start)

#@jit   #位置2
def to_dict(row, description):
    """
    记录转为字典
    """
    item = dict()
    for i, field in enumerate(description):
        field_name = field[0]
        item[field_name] = row[i]
    return item

test_for()
 

 结果

 
python3           0.0033788681030273438
python3 +位置1jit 0.08921098709106445
python3 + 位置1jit+位置2jit  3.846426010131836
pypy              0.0065860748291015625
 
对比结果,发现如果是非计算问题,引入即时编译,反而导致性能下降。实际python在非计算问题上性能很好。
 
 

来源

 

 

Avatar_small
f88tw 说:
2020年10月09日 14:56

敬启者:个人小网站希望大家多多支持 感谢您对我们热心的支持 f88tw┃华歌尔┃I appreciate your kind assistance. f88tw|墓园|捡骨流程|捡骨费用|捡骨时间|禁忌|捡骨颜色|捡骨师|新竹|时间|台北|桃园|苗栗|头份|火化|晋塔|安葬|法事|捡骨|看日子|墓穴|墓园|坟墓|看日子|乞丐|http://mypaper.m.pchome.com.tw/f88tw

Avatar_small
hassan 说:
2020年10月10日 13:18

wow this saintly however ,I love your enter plus nice pics might be part personss negative love being defrent mind total poeple , Tax consulting

Avatar_small
hassan 说:
2020年10月22日 21:09

If this is violated, the transaction will request a refund. Please be careful 먹튀폴리스

Avatar_small
hassan 说:
2020年10月24日 18:15

If this is violated, the transaction will request a refund. Please be careful. 토토사이트

Avatar_small
hassan 说:
2020年10月24日 18:28

If this is violated, the transaction will request a refund. Please be careful. 토토사이트

Avatar_small
hassan 说:
2020年10月26日 16:45

On this subject internet page, you'll see my best information, be sure to look over this level of detail. buy youtube views and likes

Avatar_small
hassan 说:
2020年10月29日 21:02

Mmm.. estimable to be here in your report or notify, whatever, I repute I should moreover process strong for my have website want I play some salubrious further updated busy in your location. best internet provider montreal

Avatar_small
hassan 说:
2020年11月06日 13:15

This is very interesting content! I have thoroughly enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great. buy Cialis 40 mg over the counter with free shipping

Avatar_small
Digital_Zone 说:
2020年12月01日 15:41

I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. Zonnepanelen kopen

Avatar_small
Digital_Zone 说:
2020年12月01日 15:49

This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! Wat is leadgeneratie

Avatar_small
Digital_Zone 说:
2020年12月01日 15:53

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Horeca Koeling

Avatar_small
Digital_Zone 说:
2020年12月01日 16:03

Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. Erotische massage

Avatar_small
Digital_Zone 说:
2020年12月01日 16:08

An interesting dialogue is price comment. I feel that it is best to write more on this matter, it may not be a taboo topic however usually individuals are not enough to talk on such topics. To the next. Cheers. Prijs webdesign Alken

Avatar_small
Digital_Zone 说:
2020年12月01日 16:12

It is a good site post without fail. Not too many people would actually, the way you just did. I am impressed that there is so much information about this subject that has been uncovered and you’ve defeated yourself this time, with so much quality. Good Works! Definitie leadgeneratie

Avatar_small
Digital_Zone 说:
2020年12月01日 16:15

Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it. Airco

Avatar_small
Digital_Zone 说:
2020年12月01日 16:19

It is truly a well-researched content and excellent wording. I got so engaged in this material that I couldn’t wait reading. I am impressed with your work and skill. Thanks. Zonnepanelen

Avatar_small
Digital_Zone 说:
2020年12月01日 16:23

Wow, What an Outstanding post. I found this too much informatics. It is what I was seeking for. I would like to recommend you that please keep sharing such type of info.If possible, Thanks. Leadgeneratie

Avatar_small
Digital_Zone 说:
2020年12月01日 16:28

Superior post, keep up with this exceptional work. It's nice to know that this topic is being also covered on this web site so cheers for taking the time to discuss this! Thanks again and again! Zonnepanelen plaatsen

Avatar_small
Digital_Zone 说:
2020年12月01日 16:32

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. Prijs webdesign Kortessem

Avatar_small
Digital_Zone 说:
2020年12月01日 16:36

I admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well. Airco Aalst

Avatar_small
Digital_Zone 说:
2020年12月01日 16:40

nice post, keep up with this interesting work. It really is good to know that this topic is being covered also on this web site so cheers for taking time to discuss this! Leadgeneratie marketing

Avatar_small
Digital_Zone 说:
2020年12月01日 16:43

I know your expertise on this. I must say we should have an online discussion on this. Writing only comments will close the discussion straight away! And will restrict the benefits from this information. Erotische massages

Avatar_small
Digital_Zone 说:
2020年12月01日 16:47

This article was written by a real thinking writer without a doubt. I agree many of the with the solid points made by the writer. I’ll be back day in and day for further new updates. Website laten maken

Avatar_small
Digital_Zone 说:
2020年12月01日 17:57

I just couldn't leave your website before telling you that I truly enjoyed the top quality info you present to your visitors? Will be back again frequently to check up on new posts. Prijs airco

Avatar_small
Digital_Zone 说:
2020年12月01日 18:02

I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. Waarom is leadgeneratie belangrijk?

Avatar_small
Digital_Zone 说:
2020年12月01日 18:06

Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. There tend to be not many people who can certainly write not so simple posts that artistically. Continue the nice writing Zonnepanelen offerte

Avatar_small
Digital_Zone 说:
2020年12月01日 18:10

Thank you so much for such a well-written article. It’s full of insightful information. Your point of view is the best among many without fail.For certain, It is one of the best blogs in my opinion. Webdesign Genk

Avatar_small
Digital_Zone 说:
2020年12月01日 18:13

Fabulous post, you have denoted out some fantastic points, I likewise think this s a very wonderful website. I will visit again for more quality contents and also, recommend this site to all. Thanks. Wat is SEO?

Avatar_small
Digital_Zone 说:
2020年12月01日 18:20

I am thankful to you for sharing this plethora of useful information. I found this resource utmost beneficial for me. Thanks a lot for hard work. Leadgeneratie betekenis

Avatar_small
Digital_Zone 说:
2020年12月01日 18:25

The content is utmost interesting! I have completely enjoyed reading your points and have come to the conclusion that you are right about many of them. You are great, and your efforts are outstanding! Prijs webdesign Genk

Avatar_small
Digital_Zone 说:
2020年12月01日 18:30

It is included in my habit that I often visit blogs in my free time, so after landing on your blog. I have thoroughly impressed with it and decided to take out some precious time to visit it again and again. Thanks. Definitie SEO?

Avatar_small
Digital_Zone 说:
2020年12月01日 18:36

Succeed! It could be one of the most useful blogs we have ever come across on the subject. Excellent info! I’m also an expert in this topic so I can understand your effort very well. Thanks for the huge help. Inbound marketing gebruiken om organische SEO leads te genereren

Avatar_small
Digital_Zone 说:
2020年12月01日 18:40

Hey, I am so thrilled I found your blog, I am here now and could just like to say thank for a tremendous post and all round interesting website. Please do keep up the great work. I cannot be without visiting your blog again and again. Waarom is SEO belangrijk?


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter