Redian新闻
>
关于c++的效率再给个例子
avatar
关于c++的效率再给个例子# Programming - 葵花宝典
s*p
1
海归朋友回国后,他觉得与父母的观念差异已经超越了“代沟”的程度。他希望保持自己的独立性,而家人却希望恢复盼望已久的安定的家庭格局。以及在文化观念上的认同与冲突的交替显现都打破了刚刚归来时那种其乐融融的家庭氛围。
回国的朋友细数了自己的烦恼:择业时和父母会产生不同的意见。大多数海归都希望根据自己的兴趣选择工作,而父母却希望儿女选择一份有稳定收入来源的工作,从而过上安稳的生活。如此一来,冲突难以避免。家人为啥非要干预选择呢?因为父母觉得这些海归的想法不符合国情。
然而,更另海归朋友们头痛的是,在择偶时与父母存在的分歧更大。在这个问题上,父母总担心子女“遇人不淑”而试图“包办”婚姻。相比这一方面,找工作时候产生的矛盾简直算“温和”,即便是生活在气氛号称“民主、自由”的家庭,婚嫁大事上也不见得完全合拍。
对此我认为,现在不仅仅是海归家庭存在这些问题,许多新时代出生的子女和父母的代沟和思想观念冲突已经很大了。解决理解沟通冲突的最大关键是中国的家庭环境普遍望子成龙,父辈一般从来没有或很少“浸入”海外生活和接受异域文化。两代人之间原本就存在着很大代沟,而海归子女长期的海外独立生活的经历又加大了其与亲人间的思想观念差异。其实化解这其中的代沟,最好的办法就是沟通。多和父母谈谈自己的想法以争取他们的理解。尽管很多时候,在他们看来,我们的想法是不现实的。但是多和他们交流以告诉他们我们是怎么想的和为什么要这样做以及我们有哪些实力。他们是会试着理解和支持我们的。通过努力工作去向父母证明我们的选择,也是留学归来后再次成长的过程。
avatar
f*0
2
大概18%的cut吧。好多职位都冻结了。明年可能又要降10%工资了。希望不要裁人。
avatar
b*k
3
想在加州注册一个LLC。很多Legal网站说必须。
Assign an agent for service of process. Also referred to as the resident
agent, this is any individual who resides in California or a business that
has filed an appropriate certificate. This person or business is the entity
that will receive service of process for any lawsuit naming the LLC as
defendant.
agent不就是接受转发重要邮件吗?有必要吗?用自己注册的LLC可以吗?
谢谢!
avatar
l*o
4
1. Free $100 + Extra $60 Cashback Bonus from Discover More® Card 最适合
中美间使用的多彩卡片Discover信用卡 11/15-12/31双倍holiday bonus
http://bankbonus.spaces.live.com/blog/
2.Chase Freedom Visa- $100 Bonus Cash Back
http://bankbonus.spaces.live.com/blog/
3. 免费的250刀 Chase SapphireSM Preferred Card需要满足这个offer的条件 优先
考虑哈 里面有指导如何满足条件
http://bankbonus.spaces.live.com/blog/
4.Chase 力作 continental onepass信用卡 首笔消费就送25000miles(无金额限制)
http://bankbonus.spaces.live.com/blog/
最近申请chase家的这个信用卡会弹出一个页面,写着Before you go…We hope you
will reconsider 难不成他们家最近被人拿太多这个免费机票了 不用对它客气,
赶紧点击Return&Apply, 拿到落袋为安。
http://bankbonus.spaces.live.com/blog/
。。。。都有详尽的每个步骤申请和使用兑换积分的细节和相应链接,请收藏转发
http://bankbonus.spaces.live.com/blog/
avatar
w*3
5
中国是诗歌的国度,有许多诗都有很大的影响,这里要评的是影响“最大”的十首诗,
而并不是最好的十首诗。因为要影响大,除了要写得好之外,还必须通俗易懂、易记。
第一首:李白《静夜思》
床前明月光,疑是地上霜。
举头望明月,低头思故乡。
提到思乡,诗仙的这首诗是所有只要是稍识文墨的中国人第一时间想起的。这首诗明白
如话,读起来琅琅上口,表达的是人们普遍共鸣的思乡之情,所以千百年来广为传诵,
成了炎黄子孙最熟悉的古典诗歌。
第二首:孟郊《游子吟》
慈母手中线,游子身上衣。
临行密密缝,意恐迟迟归。
谁言寸草心,报得三春晖。
这是一首歌颂母爱的诗。诗中亲切真淳地吟颂人类最伟大的情感--母爱。尤其是诗的
最后两句,以通俗的比喻,寄讬赤子炽烈的情怀,对于春日般的母爱,被广为传颂。
第三首:白居易《赋得古原草送别》
离离原上草,一岁一枯荣。
野火烧不尽,春风吹又生。
远芳侵古道,晴翠接荒城。
又送王孙去,萋萋满别情。
白居易的这首诗尤以第二句最为有名,影响最大。“野火烧不尽,春风吹又生”极为形
象生动地表现了野草顽强的生命力,激励了多少辈中国人奋发向前。
第四首:曹植《七步诗》
煮豆燃豆萁,豆在釜中泣。
本是同根生,相煎何太急?
这首诗连同这个典故,都广为中国人熟知。曹植运用了十分贴切、浅显生动的比喻表达
出自己的情感,并因此逃过一劫。每当再出现兄弟相争时,中国人都会想起这首诗,“
本是同根生,相煎何太急?”
第五首:王之涣《登鹳雀楼》
白日依山尽,黄河入海流。
欲穷千里目,更上一层楼。
“欲穷千里目”,写诗人一种无止境探求的愿望,还想看得更远,看到目力所能达到的
地方,唯一的办法就是要站得更高些,“更上一层楼”。
与君离别意,同是宦游人。(绘图:志清/看中国)
第六首:王维《九月九日忆山东兄弟》
独在异乡为异客,每逢佳节倍思亲。
遥知兄弟登高处,遍插茱萸少一人。
这首诗写游子思乡怀亲。异乡异土生活的孤独凄然,因而时时怀乡思人,遇到佳节良辰
,思念倍加。诗意反复跳跃,含蓄深沉,既朴素自然,又曲折有致。“每逢佳节倍思亲
”千百年来,成为游子思念的名言,打动多少游子离人之心。
第七首:《诗经》第一首《关雎》
关关雎鸠,在河之洲。
窈窕淑女,君子好逑。
参差荇菜,左右流之。
窈窕淑女,寤寐求之。
求之不得,寤寐思服。
悠哉悠哉,辗转反侧。
参差荇菜,左右采之。
窈窕淑女,琴瑟友之。
参差荇菜,左右毛之。
窈窕淑女,钟鼓乐之。
《诗经》是中国诗歌之始,其中不乏千古名句,尤以第一首广为人知。中国的爱情诗也
有很多,其中不乏千古名句,但尤以《关雎》影响最大。
第八首:李清照《夏日绝句》
生当作人杰,死亦为鬼雄。
至今思项羽,不肯过江东。
女词人李清照这首慷慨激昂的诗起调高亢,人活着就要作人中的豪杰,为国家建功立业
;死也要为国捐躯,成为鬼中的英雄。诗人鞭挞南宋当权派的无耻行径,借古讽今,正
气凛然。如此慷慨雄健、掷地有声的诗篇,出自女性之手,实在是压倒须眉了。
第九首:王勃《送杜少府之任蜀州》
城阙辅三秦,风烟望五津。
与君离别意,同是宦游人。
海内存知己,天涯若比邻。
无为在岐路,儿女共沾巾。
这是送别的名作。诗意慰勉勿在离别之时悲哀。第三联“海内存知己,天涯若比邻”,
奇峰突起,高度地概括了“友情深厚,江山难阻”的情景,伟词自铸,传之千古,有口
皆碑。
第十首:李绅《悯农》
锄禾日当午,汗滴禾下土。
谁知盘中餐,粒粒皆辛苦。
这首诗是写劳动的艰辛,劳动果实来之不易。“谁知盘中餐,粒粒皆辛苦”的感叹和告
诫免于空洞抽象的说教,而成为有血有肉、意蕴深远的格言。
avatar
b*s
6
template
long long factorial()
{
return factorial(NUM - 1) * NUM;
}
然后对0,1特例化一下
现在问,运行时计算 factorial<20> 需要多少次运算?
20次乘法?
答案是一次内存读操作就行了
avatar
S*p
7
如果你人在加州就不需要,
avatar
w*g
8
连我都要说你这个是cheating。C++的模板元编程的对手是haskell。回去想个更好的例
子来。

【在 b*******s 的大作中提到】
: template
: long long factorial()
: {
: return factorial(NUM - 1) * NUM;
: }
: 然后对0,1特例化一下
: 现在问,运行时计算 factorial<20> 需要多少次运算?
: 20次乘法?
: 答案是一次内存读操作就行了

avatar
B*n
9
你人在加州就不需要,外地的话需要实体地址
我是在ups租了mail box作为公司地址,其实算起来比agent贵
avatar
b*s
10
想象一下你写的关于数值计算的类库
能提供O(1)的阶乘算法

【在 b*******s 的大作中提到】
: template
: long long factorial()
: {
: return factorial(NUM - 1) * NUM;
: }
: 然后对0,1特例化一下
: 现在问,运行时计算 factorial<20> 需要多少次运算?
: 20次乘法?
: 答案是一次内存读操作就行了

avatar
b*s
11
我只是在介绍语言特性,c++用来写库还是很爽的

【在 w***g 的大作中提到】
: 连我都要说你这个是cheating。C++的模板元编程的对手是haskell。回去想个更好的例
: 子来。

avatar
b*s
12
我换constexpr怎么样
这个总不是meta programming了吧

【在 w***g 的大作中提到】
: 连我都要说你这个是cheating。C++的模板元编程的对手是haskell。回去想个更好的例
: 子来。

avatar
g*e
13

这个是说编译的时候把他算好了吗?

【在 b*******s 的大作中提到】
: template
: long long factorial()
: {
: return factorial(NUM - 1) * NUM;
: }
: 然后对0,1特例化一下
: 现在问,运行时计算 factorial<20> 需要多少次运算?
: 20次乘法?
: 答案是一次内存读操作就行了

avatar
b*s
14
是的,编译期决定,效率比c高

【在 g*********e 的大作中提到】
:
: 这个是说编译的时候把他算好了吗?

avatar
n*l
15
that is pretty much useless if n varies in run time.
a better approach is to use plain c and build up a look up table.
this is a good example for c++ "expert" to mind masturbating on
features that do not matter.
plus, template is really ugly looking.

【在 b*******s 的大作中提到】
: 是的,编译期决定,效率比c高
avatar
b*s
16
这个设计简直是灾难

【在 n****l 的大作中提到】
: that is pretty much useless if n varies in run time.
: a better approach is to use plain c and build up a look up table.
: this is a good example for c++ "expert" to mind masturbating on
: features that do not matter.
: plus, template is really ugly looking.

avatar
N*K
17
数学运算库 不用template 就是搞笑

【在 n****l 的大作中提到】
: that is pretty much useless if n varies in run time.
: a better approach is to use plain c and build up a look up table.
: this is a good example for c++ "expert" to mind masturbating on
: features that do not matter.
: plus, template is really ugly looking.

avatar
a*a
18
with some template tricks, the lookup table can be built up to a constant N
at compile time. Run time for any n
【在 n****l 的大作中提到】
: that is pretty much useless if n varies in run time.
: a better approach is to use plain c and build up a look up table.
: this is a good example for c++ "expert" to mind masturbating on
: features that do not matter.
: plus, template is really ugly looking.

avatar
g*g
19
You can put it in DB and look up a table 100 times you memory can hold any
time. What's the point?

N

【在 a*********a 的大作中提到】
: with some template tricks, the lookup table can be built up to a constant N
: at compile time. Run time for any n
avatar
a*a
20
We are talking about shaving cpu cycles and your suggestion is to introduce
IO?
I know netflix does not mind making its users wait for seconds or minutes,
but in my business, 1 millisecond slower than competitors means annihilation.

【在 g*****g 的大作中提到】
: You can put it in DB and look up a table 100 times you memory can hold any
: time. What's the point?
:
: N

avatar
g*g
21
It doesn't matter what business, you cant preload the data and compiler
trick is the only way?
Should Nasdaq hardcode all ticks to avoid some IO? That's just ridiculous
argument.

introduce
annihilation.

【在 a*********a 的大作中提到】
: We are talking about shaving cpu cycles and your suggestion is to introduce
: IO?
: I know netflix does not mind making its users wait for seconds or minutes,
: but in my business, 1 millisecond slower than competitors means annihilation.

avatar
n*l
22
no more template tricks, please. what about the compiling error of
template code? is that nearly sane now?

N

【在 a*********a 的大作中提到】
: with some template tricks, the lookup table can be built up to a constant N
: at compile time. Run time for any n
avatar
b*s
23
the err msgs are as bad as ever

【在 n****l 的大作中提到】
: no more template tricks, please. what about the compiling error of
: template code? is that nearly sane now?
:
: N

avatar
T*i
24
Once you get used to it, it is not that bad any more.

【在 b*******s 的大作中提到】
: the err msgs are as bad as ever
avatar
b*s
25
我已经习惯了,但是的确是丑陋了一点

【在 T********i 的大作中提到】
: Once you get used to it, it is not that bad any more.
avatar
f*y
26
factorial<20>本来就是一个常数,C++和Java都只需要读一下内存。

【在 b*******s 的大作中提到】
: template
: long long factorial()
: {
: return factorial(NUM - 1) * NUM;
: }
: 然后对0,1特例化一下
: 现在问,运行时计算 factorial<20> 需要多少次运算?
: 20次乘法?
: 答案是一次内存读操作就行了

avatar
a*a
27
preloading sometimes is not an option Say your program crash in the middle
of a trading session, each second you waste reloading the DB is money.
now if you are preloading, you now can't do 100 times the memory can hold
can you? So if it is a limited set of fixed data, compile once and be done
vs read every time on start up, which one is better?

【在 g*****g 的大作中提到】
: It doesn't matter what business, you cant preload the data and compiler
: trick is the only way?
: Should Nasdaq hardcode all ticks to avoid some IO? That's just ridiculous
: argument.
:
: introduce
: annihilation.

avatar
g*g
28
So you don't need to recompile and redeploy every time you add a tick. How
hard is it to understand that ? Separation of code and data is basic
principle. And while I can't preload 100 times memory of data, I can pick
what data to cache and at what time, with simple algorithm like LRU, can you?
Trying to avoid crash is the right way to go, not saving a few seconds after
crash. I can't believe this question is even being asked.

【在 a*********a 的大作中提到】
: preloading sometimes is not an option Say your program crash in the middle
: of a trading session, each second you waste reloading the DB is money.
: now if you are preloading, you now can't do 100 times the memory can hold
: can you? So if it is a limited set of fixed data, compile once and be done
: vs read every time on start up, which one is better?

avatar
l*s
29
yes for sure.

【在 n****l 的大作中提到】
: no more template tricks, please. what about the compiling error of
: template code? is that nearly sane now?
:
: N

avatar
l*s
30
I think it is.

【在 b*******s 的大作中提到】
: 我换constexpr怎么样
: 这个总不是meta programming了吧

avatar
f*y
31
这个真的是你自己不行而已。

【在 n****l 的大作中提到】
: no more template tricks, please. what about the compiling error of
: template code? is that nearly sane now?
:
: N

avatar
k*g
32

有 static_assert 好不好

【在 n****l 的大作中提到】
: no more template tricks, please. what about the compiling error of
: template code? is that nearly sane now?
:
: N

avatar
a*a
33
hmm, I thought long and hard how can a simple Fibonacci violate separation
of data and code.
Then I realized, that we were demonstrating how static computation can be
used to optimize run time. I said you can create a static table of fib
for nimposed separation of data and code so algorithms to compute Fibonacci at
compile time are outlawed.
Very very impressive PPT skills you possess there! Your legal team should
have asked your advices, perhaps then you guys wouldn't have lost the net
neutrality case.
Now since you mentioned avoiding crash. Let s see. We all know that
Fibonacci overflows an integer at about n=50. With template techniques,
simple specialize fib<50> to a false static assertion, all attempt to access
an overflowing fibonacci would produce compile time errors! There is no
possibility of run time overflow due to this CODE. On the hand, you DATA
approach must be have run time checks for validity, which in best cases
introduces unnecessary branching (albeit most likely an extremely
predictable branch), in worst case leads to crashes.
You also mentioned compilation cost. If you were familiar with template
techniques, you would already have seen that what I proposed already
sacrificed the 0 run time of typical template compile time computation. That
means I would be using forced instantiation, where all the fib templates
with (n is
not inlined as 8 but have to deref an address. This C file is pretty
compiled and
and forgot about.

you?
after

【在 g*****g 的大作中提到】
: So you don't need to recompile and redeploy every time you add a tick. How
: hard is it to understand that ? Separation of code and data is basic
: principle. And while I can't preload 100 times memory of data, I can pick
: what data to cache and at what time, with simple algorithm like LRU, can you?
: Trying to avoid crash is the right way to go, not saving a few seconds after
: crash. I can't believe this question is even being asked.

avatar
b*s
34
连template都不是

【在 l*********s 的大作中提到】
: I think it is.
avatar
l*s
35
没这个东东concept就玩不了,而concept对template非常有用。

【在 b*******s 的大作中提到】
: 连template都不是
avatar
g*g
36
And who told you Fib function overflow at 50? You can't fit the result in an
Integer, doesn't mean that you can't fit it as a String. If you are going to
provide a website for people to query Fib, you think they'll never input
more than 50?
Your argument proves exactly why compiler trick is so limited it's barely
useful. You can do 50, and I don't see a problem doing 5000. 100 times more
than you can do as I said.

【在 a*********a 的大作中提到】
: hmm, I thought long and hard how can a simple Fibonacci violate separation
: of data and code.
: Then I realized, that we were demonstrating how static computation can be
: used to optimize run time. I said you can create a static table of fib
: for n: imposed separation of data and code so algorithms to compute Fibonacci at
: compile time are outlawed.
: Very very impressive PPT skills you possess there! Your legal team should
: have asked your advices, perhaps then you guys wouldn't have lost the net
: neutrality case.

avatar
d*f
37
你跟java程序员较什么劲,人家脑子里根本没有内存好不好

【在 b*******s 的大作中提到】
: template
: long long factorial()
: {
: return factorial(NUM - 1) * NUM;
: }
: 然后对0,1特例化一下
: 现在问,运行时计算 factorial<20> 需要多少次运算?
: 20次乘法?
: 答案是一次内存读操作就行了

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。