用C ++加快速度 [英] speeding things up with C++

查看:81
本文介绍了用C ++加快速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经完成了所有必需的分析并且相当深入地考虑了我的python代码的效率,但我仍然需要加速

up the up我正在做的最内心的事情。


基本上,我需要传递一个只包含

整数的6元组列表给我新的悲伤必要的超级快速编译语言

函数,我不期待写作:


输入:[(1,2,3,4,5,6), (7,8,9,10,11,12),...]

并且在经过多次处理器资源颠簸之后,返回

看起来的数据像这样的Python调用环境:


输出:[((1,2),(1,),(12,),(13),(1,7,11) ),(9,)),(另一个

嵌套元组,如前一个),....]


返回列表的每个成员都是包含6个元组的元组,以及这6个元组中每个元组至少有一个整数成员的
。它也可以接受
,返回值完全是嵌套列表

而不是将两个最里面的序列类型作为元组。


我可能想要使用类似C ++的东西,因为我要去

需要使用STL向量和设置我在算法中做什么

我想加快速度。 IIRC Boost元组有点痛苦,比10元素更多+ +并不是真的必不可少的我使用一个非变量的

数据类型会是一个小的封装了一个更大的

系统。


无论如何,我可以很快找出一些被黑客攻击的方式来获取

数据进入我的函数给出了在最坏的情况下我可以利用

的优势,知道每个输入元组总是有6个元素,并简单地传入一个大数组整数。是的,我知道这是有点迟钝的,但我说的是最糟糕的情况,假设非常紧张,没有时间深入研究SWIG或其他什么。同样地,

将结果作为母亲返回所有字符串并不是太困难我可以很容易地解析所有字符串。


但是,我希望读到这篇文章的人能够告诉我,我是一个完全悲观主义者,而且事实上并不是很难做到br />
我想用SWIG做什么。我不是要求一个完整的解决方案,

更像是一些实际上已经做过类似事情的人的一般指示。


作为一个额外的奖励,如果使用Ocaml

作为胆量而不是C ++,我不会很容易这样做,我很乐意知道它。

I''ve done all the requisite profiling and thought fairly deeply about
the efficiency of my python code, but am still going to have to speed
up the innermost guts of what I am doing.

Essentially, I need to pass a list of 6-tuples containing only
integers to my new sadly necessary super-fast compiled language
function which i am not looking forward to writing:

input: [(1,2,3,4,5,6), (7,8,9,10,11,12),...]

and after much thrashing of processor resources, return data which
looks like this to the Python calling environment:

output: [( (1, 2), (1,), (12,), (13), (1, 7, 11), (9,) ), ( another
nested tuple like preceding one ), .... ]

Each member of the returned list is a tuple containing 6 tuples, and
each of those 6 tuples has at least one integer member. It would also
be acceptable for the return values to be entirely nested lists
instead of having the two innermost sequence types as tuples.

I probably want to be using something like C++ because i''m going to
need to use STL vectors and sets for what i''m doing in the algorithm
i''m trying to speed up. IIRC Boost tuple is a bit painful for more
than 10 elements + isn''t really essential that I use a a non-mutable
data type in what will be a small encapsulated bit of a much larger
system.

Anyway, I can probably very quickly figure out some hacked way to get
the data into my function given that in the worst case I could take
advantage of the knowledge that each input tuple always has 6
elements, and simply pass in a big array of ints. Yes, I know this is
a bit retarded, but I''m talking worst case assuming on very tight
schedule and no time to delve deeply into SWIG or whatever. Similarly
it wouldn''t be too difficult to return the result as the mother all of
all strings which i could then parse fairly easily.

However, I hope someone reading this will be able to tell me that I''m
being a total pessimist and that in fact it isn''t very difficult to do
what I want to do using SWIG. I''m not asking for a complete solution,
more like some general pointers from someone who has actually done
something similar before.

As an added bonus, I wouldn''t if this is ''easily'' doable using Ocaml
as the guts instead of C++, I''d be happy to know about it.

推荐答案

5月26日上午11点19分,bullockbefriending bard< kinch1 ... @ gmail.com>

写道:
On May 26, 11:19 am, bullockbefriending bard <kinch1...@gmail.com>
wrote:

但是,我希望有人读这篇文章能告诉我,我是

作为一个完全的悲观主义者,事实上,使用SWIG做我想做的事情并不是很困难。我不是要求一个完整的解决方案,

更像是一些实际上已经做过类似事情的人的一般指示。
However, I hope someone reading this will be able to tell me that I''m
being a total pessimist and that in fact it isn''t very difficult to do
what I want to do using SWIG. I''m not asking for a complete solution,
more like some general pointers from someone who has actually done
something similar before.



我用ctypes做这样的事情( http://docs.python.org/lib/module-ctypes.html

)!

我''我相信你可以找到一些方法来传递/返回你的C / $
++库中的数据。

最简单的方法 - 使用字符串或数组,但如果你深入了解

ctyles文档,

我相信你会找到更好的解决方案!


祝你好运,

- 错误记录

I do stuff like that with ctypes ( http://docs.python.org/lib/module-ctypes.html
)!
I''m sure you can figure out some way to pass/return data to/from your C
++ lib.
The easiest way - use strings or arrays, but if you dig deeper into
ctyles documentation,
I''m sure you will find a better solution!

Good luck,
-- misreckoning


谢谢!我会调查一下。


5月27日上午5:35,Che Guevara< sreckotoro ... @ gmail.comwrote:
thanks! i''ll look into this.

On May 27, 5:35 am, Che Guevara <sreckotoro...@gmail.comwrote:

5月26日上午11点19分,bullockbefriending bard< kinch1 ... @ gmail.com>

写道:
On May 26, 11:19 am, bullockbefriending bard <kinch1...@gmail.com>
wrote:

但是,我希望读到这篇文章的人能够告诉我,我是一个悲观主义者,而且实际上并不是很难做到br />
我想用SWIG做什么。我不是要求一个完整的解决方案,

更像是一些实际上已经做过类似事情的人的一般指示。
However, I hope someone reading this will be able to tell me that I''m
being a total pessimist and that in fact it isn''t very difficult to do
what I want to do using SWIG. I''m not asking for a complete solution,
more like some general pointers from someone who has actually done
something similar before.



我用ctypes做这样的事情( http://docs.python.org/lib/module-ctypes.html

)!

我''我相信你可以找到一些方法来传递/返回你的C / $
++库中的数据。

最简单的方法 - 使用字符串或数组,但如果你深入了解

ctyles文档,

我相信你会找到更好的解决方案!


祝你好运,

- 错误记入


I do stuff like that with ctypes (http://docs.python.org/lib/module-ctypes.html
)!
I''m sure you can figure out some way to pass/return data to/from your C
++ lib.
The easiest way - use strings or arrays, but if you dig deeper into
ctyles documentation,
I''m sure you will find a better solution!

Good luck,
-- misreckoning



我想知道Jython是否可能是答案?对于程序中时间关键的部分,Java比Python要快得多b / b
。有没有人

有经验从运行的jython程序中获取嵌套列表/元组

等数据结构到java例程中(然后又返回

) )?

I wonder if Jython might be the answer? Java is going to be faster
than Python for the time-critical part of my program. Does anybody
have experience getting data structures like nested lists / tuples
into a java routine from a running jython program (and then back
again)?


这篇关于用C ++加快速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆