I have the following code to profile std::vector performance vs std::list for various N.  void vectorPerf(size_t n) {    std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();    std::vector&lt;size_t&gt; cache;    for (size_t i = 0; i &lt; n; i++) {       cache.push_back(i);    }    std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();     auto duration = std::chrono::duration_cast&lt;std::chrono::microseconds&gt;(t2-t1).count();     std::cout &lt;&lt; duration &lt;&lt; " us." &lt;&lt; "\n";     return; }  void listPerf(size_t n) {    std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();    std::list&lt;size_t&gt; cache;    for (size_t i = 0; i &lt; n; i++) {       cache.push_back(i);    }    std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();     auto duration = std::chrono::duration_cast&lt;std::chrono::microseconds&gt;(t2-t1).count();     std::cout &lt;&lt; duration &lt;&lt; " us." &lt;&lt; "\n";     return; }  int main(int argc, char** argv) {     if (argc != 2) {       return -1;    }    std::stringstream ss(argv[1]);    size_t n;    ss &gt;&gt; n;    vectorPerf(n);    std::cout &lt;&lt; "\n";    listPerf(n);    std::cout &lt;&lt; "\n"; }   For multiple runs of the same set of N, I get results where the results are consistently of the same order as the numbers below:  N       std::vector  std::list 1000    46           116 2000    85           217 5000    196          575 10000   420          1215 100000  3188         10497 1000000 34489        114330   What I am wondering is how come the performance of std::list is consistently worse then std::vector. For std::vector I would have expected the performance to be amortized O(N), because the internal object underpinning std::vector would need to be resized time to time. Since all I am doing is inserting an element to the end of the list I would have expected std::list to be O(1). So that would suggest that std::list would do better than std::vector but the opposite seems to be true.   I would appreciate if someone can shed some light on why this is happening. I am compiling on MacOS 10.12.6 using g++ on a 2015 MBP.  Thanks.   EDIT: I now understand that std::vector::push_back() is amortized O(1). However, what is not clear to me is why does std::list::push_back() perform consistently worse than std::vector::push_back()?
Apparently ;-) the standard containers provide some form of guarantees.  What type of guarantees and what exactly are the differences between the different types of container?  Working from  (about ) I have come up with this:  Container Types: ================ Container:     Forward Container         Reverse Container             Random Access Container     Sequence         Front Insert Sequence         Back  Insert Sequence     Associative Container         Simple   Associative Container         Pair     Associative Container         Sorted   Associative Container         Multiple Associative Container  Container Types mapped to Standard Containers =============================================  std::vector:    Sequence    Back        Sequence                    Forward/Reverse/Random Container std::deque:     Sequence    Front/Back  Sequence                    Forward/Reverse/Random Container std::list:      Sequence    Front/Back  Sequence                    Forward/Reverse Container std::set:       Sorted/Simple/Unique    Associative Container       Forward Container std::map:       Sorted/Pair/Unique      Associative Container       Forward Container std::multiset:  Sorted/Simple/Multiple  Associative Container       Forward Container std::multimap:  Sorted/Pair/Multiple    Associative Container       Forward Container   Container Guarantees: =====================                                                                                    Simp                                                                                   or                           For   Rev  Rand        Front  Back  Assoc        Sort   Mult                     Cont: Cont: Cont Cont: Sequ: Sequ:  Sequ: Cont:        Cont:  Cont: Copy    Const:      O(n) Fill    Const:                             O(n) begin()             O(1) end()               O(1) rbegin()                        O(1) rend()                          O(1) front()                                    O(1) push_front()                                     O(1) pop_front()                                      O(1) push_back()                                             O(1) pop_back()                                              O(1) Insert()                                                                          O(ln(n)) Insert: fill                               O(n) Insert: range                              O(n)                                   O(kln(n)+n) size()              O(n) swap()              O(1) erase key                                                     O(ln(n)) erase element                                                 O(1) erase range                                                   O(ln(n)+S) count()                                                       O(log(n)+k) find()                                                        O(ln(n)) equal range                                                   O(ln(n)) Lower Bound/Upper Bound                                                    O(ln(n)) Equality                  O(n) InEquality                O(n) Element Access                       O(1)
Custom command does not reference a label created with a previous custom command What 70s (60s?) TV show / TV movie had a generation ship whose inhabitants did not know they were on a spaceship? I have the vaguest memory of a TV show (maybe a BBC import?) in which the protagonists were moving through the sections of a massive generation ship whose inhabitants had forgotten that they were on a spaceship... I know there was an RPG with the same plot (which, after all, is a pretty great blank slate) but I definitely feel I saw this on a static-filled 13" B&amp;W TV back in the day... How to set programmatically multiple arguments for views contextual filters How to set programmatically multiple arguments for views contextual filters?  I can do it with one argument, it works great, but not with multiple arguments.  I want to select all nodes created by a list of people, but views only takes first in array into consideration:  $array = array(3250,32); $view = views_get_view('myview'); $view-&gt;set_display("myblock"); $view-&gt;set_arguments($array); $view-&gt;pre_execute(); $view-&gt;execute(); $content = $view-&gt;render();    Am I doing something wrong? No space following macro without argument Rebel flight suits include an ejection harness, Biggs tells Porkins to eject. This seems to suggest that Rebel fighters have an ejection system.  How would they operate for different fighters? Does the whole cockpit separate? Do they function like current aircraft ejection systems - if so what protects the pilot from the vacuum of space? Which race in Star Trek universe was the first to invent Warp technology? Humans look like late member of Warp Drive community. Klingons were capable of interstellar travel from the time of Kahless. Vulcans were in contact with Andorians from ancient times (ST: Enterprise).  Which one first invented warp capabilities: Klingons or Vulcans? Or, others? Do not show the score for users during primaries I believe that showing the post score for nomination posts during primaries is a bad idea.  When I loaded the primaries page during the election, the first thing I saw was a post voted -1. This immediately colored my impression of the post. Reading his post didn't indeed make me wish he was a moderator, but at the same point I couldn't bring myself to click on the down arrow. He wasn't an awesome candidate, but he wasn't a -2 score candidate either. Actually, I kinda wanted to sympathy upvote instead.  I want to judge by myself whether a candidate is worth or not my +1. For some of those people I don't have an opinion already, and I want to form one on my own. I don't want game theory to kick in, I don't want to be tricked into sympathy upvotes.  Having those numbers in large print as the first thing I see about them honestly prevents me from doing so. I'd rather have their avatar there.     Some people on chat do not agree with me;  I imagine they'll post explaining why I want to be aware of their opinion while forming my own.      Regardless of the discussion here, if you do prefer to hide the scores as you vote, here's the jQuery oneliner that does just that:  $(".vote-count-post").hide() Remove vote UI elements beside own question and answer posts Currently, the system makes you think you can upvote/downvote your own question/answer but then you get notified that you can't. Why have the up/down vote buttons there then?   In general, if some operation is not allowed, then don't put UI for that up or make it disabled so it is apparently disabled - no post operation error panels please?  ps: hope this is not a dupe, but if so, just comment it and I will remove  (+a joke: a user notification panel message: I deleted this file. Is this a problem? Yes/No.) Converting Raw HTTP Request into HTTPWebRequest Object Proving that $T^{2} = T$ for a linear operator on $W$ implies that $V = \operatorname{Null} T \oplus \operatorname{Range} T$ I need some advice as I am struggling with the following combinatorics exercise.  Let $k$ be a given positive integer. Show that any non-negative integer $N$ can be written uniquely in the form $$N=\binom{x_k}{k}+\binom{x_{k-1}}{k-1}+\dots+\binom{x_1}{1},$$ where $0 \leq x_1 &lt; \dots &lt; x_{k-1} &lt; x_k$.  The exercise is accompanied by this advice:  Let $x$ be such that $\binom{x}{k} \leq N &lt; \binom{x+1}{k}$. Then any possible representation has $x_k = x$. Now use induction and the fact that $N-\binom{x}{k} &lt; \binom{x}{k-1}$ to show the existence and uniqueness of the representation.  I am really stuck and thus grateful for the slightest hint on how to solve it. How do I format my code blocks? How do I post text so that it is formatted as code?  What do I need to do so that my code shows up properly &mdash; not escaped or removed &mdash; when posted? And how to get the correct syntax highlighting?     For more information, see "" in the . How to add "Refresh" option to right click menu in Lubuntu? I have many users at the place I work, expressing the notion of switching to Ubuntu.  Most of them, for whatever weird reason wanting to know if its possible to have refresh added when you right click on the desktop.   Is that possible? Here there is my proof (quite short and easy) of a rather straightforward result. The text of this question comes from a previous question of mine, where I ended up working on a wrong inequality. Here things are fixed. Still, I would like to know:  if it is sound, because absolute value always creates me some problem, and if there is a shorter (neater) way to get the result (maybe without using contradiction).    Proposition: $|d(x,y)-d(y,z)| \leq d(x,z)$. Proof: We proceed by cases.  Case 1: $d(x,y)-d(y,z) \geq 0$. Assume by contradiction that $d(x,y)-d(y,z) &gt; d(x,z)$. Hence, $d(x,y)&gt; d(y,z) + d(x,z)$, contradicting the triangle inequality.  Case 2: $d(x,y)-d(y,z) &lt; 0$. Assume by contradiction that $ - d(x,y) + d(y,z) &gt; d(x,z)$. Hence, $d(x,y) &lt; d(y,z) - d(x,z)$. By applying the triangle inequality, we have that $d(y,x) \geq d(y,z) + d(x,z)$, which is by symmetry equivalent to  $d(x,y) \geq d(y,z) + d(x,z)$, obtaining the desired contradiction. $\square$     As always, any feedback is welcome. Thank you for your time. A particular big Delta I would like to insert the below mathematical symbol, it looks like a big Delta but different. Is there command to obtain a similar shape? Is there a way to save composite node presets? Is there any way in Blender to save settings in your compositing node setup. For example say for my shadow catcher I have it setup for a hard shadow for sunlight, and then I also have a setting for diffuse light shadow for indoors. Is there any way I can save these settings individually so I can quickly switch to them rather than having to individually change the nodes every time. I have detached a process from my terminal, like this:  $ process &amp;   That terminal is now long closed, but process is still running, and I want to send some commands to that process's stdin. Is that possible? Configuring ADB for Nexus 4 on Ubuntu 11.10 I'm trying to deploy and test an Android app on my Nexus 4 from my Ubuntu 11.10 computer, but ADB doesn't recognize it. I think I need the Google USB drivers, but I cannot find instructions on how to install them on Ubuntu.  How can I install the drivers on Ubuntu 11.10 so that ADB will recognize my N4? Proof on Catalan numbers Greatest comeback in 2nd leg match