optimization

Why is slice assignment faster than `list.insert`?

假如想象 提交于 2020-01-21 03:57:24
问题 Inspired by this nice answer, Here's a benchmark: import timeit def test1(): a = [1,2,3] a.insert(0,1) def test2(): a = [1,2,3] a[0:0]=[1] print (timeit.timeit('test1()','from __main__ import test1')) print (timeit.timeit('test2()','from __main__ import test2')) For me, test2 is sligtly faster (~10%). Why is that the case? I would expect it to be slower since: slice assignment must be able to accept iterables of any length and therefore must be more general. in slice assignment, we need to

Why is this Haskell expression so slow?

时光怂恿深爱的人放手 提交于 2020-01-21 01:46:26
问题 I'm working on Project Euler Problem 14. Here's my solution. import Data.List collatzLength :: Int->Int collatzLength 1 = 1 collatzLength n | odd n = 1 + collatzLength (3 * n + 1) | even n = 1 + collatzLength (n `quot` 2) maxTuple :: (Int, Int)->(Int, Int)->Ordering maxTuple (x1, x2) (y1, y2) | x1 > y1 = GT | x1 < y1 = LT | otherwise = EQ I'm running the following out of GHCi maximumBy maxTuple [(collatzLength x, x) | x <- [1..1000000]] I know that if Haskell evaluated strictly, the time on

Buffer vs String speed: Why is String faster?

五迷三道 提交于 2020-01-20 18:31:55
问题 I have this project, called Memcached.Js, which is a port of Memcached server to Node.js. I've been playing arround with strings and buffers, comparing memory footprint and performance. For memory, there's no question that buffer is the right choice. But for my surprise the same is not true for performace. Performing string manipulation is faster than using buffer. This is what I tried: // Option 1: data.toString() - amazing, but it's the best one var commandDataStr = mdata.data.toString()

Buffer vs String speed: Why is String faster?

£可爱£侵袭症+ 提交于 2020-01-20 18:31:13
问题 I have this project, called Memcached.Js, which is a port of Memcached server to Node.js. I've been playing arround with strings and buffers, comparing memory footprint and performance. For memory, there's no question that buffer is the right choice. But for my surprise the same is not true for performace. Performing string manipulation is faster than using buffer. This is what I tried: // Option 1: data.toString() - amazing, but it's the best one var commandDataStr = mdata.data.toString()

Buffer vs String speed: Why is String faster?

∥☆過路亽.° 提交于 2020-01-20 18:31:10
问题 I have this project, called Memcached.Js, which is a port of Memcached server to Node.js. I've been playing arround with strings and buffers, comparing memory footprint and performance. For memory, there's no question that buffer is the right choice. But for my surprise the same is not true for performace. Performing string manipulation is faster than using buffer. This is what I tried: // Option 1: data.toString() - amazing, but it's the best one var commandDataStr = mdata.data.toString()

Buffer vs String speed: Why is String faster?

社会主义新天地 提交于 2020-01-20 18:30:11
问题 I have this project, called Memcached.Js, which is a port of Memcached server to Node.js. I've been playing arround with strings and buffers, comparing memory footprint and performance. For memory, there's no question that buffer is the right choice. But for my surprise the same is not true for performace. Performing string manipulation is faster than using buffer. This is what I tried: // Option 1: data.toString() - amazing, but it's the best one var commandDataStr = mdata.data.toString()

What are some tricks that a processor does to optimize code?

与世无争的帅哥 提交于 2020-01-20 18:11:40
问题 I am looking for things like reordering of code that could even break the code in the case of a multiple processor. 回答1: Wikipedia has a fairly comprehensive list of optimization techniques here. 回答2: The most important one would be memory access reordering. Absent memory fences or serializing instructions, the processor is free to reorder memory accesses. Some processor architectures have restrictions on how much they can reorder; Alpha is known for being the weakest (i.e., the one which can

How to organize minification and packaging of css and js files to speed up website?

谁说胖子不能爱 提交于 2020-01-20 17:55:27
问题 I am doing speed optimization for my website application. And I found some practises to do that. For example Best Practices for Speeding Up Your Web Site from Yahoo. Among them are: Minify JavaScript and CSS. Minimize number of HTTP Requests by combining several files (css, js) into one. My question is what infrastructure, tools and building process you use or can recommend to perform that? 回答1: According to the JavaScript Compression Rater, the most efficient tool is the YUI Compressor or

How to organize minification and packaging of css and js files to speed up website?

给你一囗甜甜゛ 提交于 2020-01-20 17:55:09
问题 I am doing speed optimization for my website application. And I found some practises to do that. For example Best Practices for Speeding Up Your Web Site from Yahoo. Among them are: Minify JavaScript and CSS. Minimize number of HTTP Requests by combining several files (css, js) into one. My question is what infrastructure, tools and building process you use or can recommend to perform that? 回答1: According to the JavaScript Compression Rater, the most efficient tool is the YUI Compressor or

How to organize minification and packaging of css and js files to speed up website?

左心房为你撑大大i 提交于 2020-01-20 17:55:03
问题 I am doing speed optimization for my website application. And I found some practises to do that. For example Best Practices for Speeding Up Your Web Site from Yahoo. Among them are: Minify JavaScript and CSS. Minimize number of HTTP Requests by combining several files (css, js) into one. My question is what infrastructure, tools and building process you use or can recommend to perform that? 回答1: According to the JavaScript Compression Rater, the most efficient tool is the YUI Compressor or