{"id":217651,"date":"2018-09-15T23:00:59","date_gmt":"2018-09-15T23:00:59","guid":{"rendered":"http:\/\/localhost\/wordpress\/index.php\/2018\/09\/15\/gsp-215-week-4-homework-optimizing-program-performance\/"},"modified":"2018-10-24T08:47:54","modified_gmt":"2018-10-24T08:47:54","slug":"gsp-215-week-4-homework-optimizing-program-performance","status":"publish","type":"post","link":"https:\/\/www.benedictsol.com\/blogs\/gsp-215-week-4-homework-optimizing-program-performance\/","title":{"rendered":"GSP 215 Week 4 Homework Optimizing Program Performance"},"content":{"rendered":"<p>Optimizing Program Performance\t\u00a0\tA programmer must write correct code that is clear and concise. There are also circumstances in which a programmer must write fast and efficient code. Processing video frames in real time must be fast. We will talk about ways to optimize code.\tGiven the following code, perform these operations to optimize the code. See Chapter 5 in the book for more details on code optimization. Please use comments to document all optimizations you have made to the code.\t1. \ufffd Using switch instead of if\t2. \ufffd Eliminating length calls out of the loop test\t3. \ufffd Put the most used variables first when initializing variables\t4. \ufffd Use prefix operations rather than postfix operations\t5. \ufffd Loop unrolling&#8221;\ufffdincrease the number of elements computed in each iteration of a loop (i.e. instead of processing arrays separately, if you have two arrays of the same length, process them in parallel)\t6. \ufffd Any other improvements you want to make\t\u00a0\t#include <iostream>\t#include <vector>\t#include <string>\tusing namespace std;\t\u00a0\t#include <iostream>\t#include <vector>\t#include <string>\tusing namespace std;\t\u00a0\tint main()\t{\t \ufffd \ufffd\u00a0 \/\/This program stores the items purchased at the grocery store. The price vector stores the prices for each item purchased.\t \ufffd \ufffd\u00a0 \/\/The product name vector stores the products purchased and the category vector stores which category the item falls under.\t \ufffd \ufffd\u00a0 \/\/Frozen foods have a 10% discount, snacks has a 5% discount, and produce has a 15% discount.\t \ufffd \ufffd\u00a0 \/\/The total amount of items purchased should be calculated with a 7% tax rate.\t \ufffd\u00a0 double sum;\t \ufffd \ufffd\u00a0 double tax,totalAmount;\t\u00a0\t \ufffd \ufffd\u00a0 vector<double> price;\t \ufffd \ufffd\u00a0 vector<string> productName;\t \ufffd \ufffd\u00a0 vector<char> category;\t \ufffd \ufffd\u00a0\t \ufffd \ufffd\u00a0 price.push_back(4.5);\t \ufffd \ufffd\u00a0 price.push_back(10);\t \ufffd \ufffd\u00a0 price.push_back(1.25);\t \ufffd \ufffd\u00a0 price.push_back(2.75);\t \ufffd \ufffd\u00a0 price.push_back(9.50);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Optimizing Program Performance \u00a0 A programmer must write correct code that is clear and concise. There are also circumstances in which a programmer must write fast and efficient code. Processing video frames in real time must be fast. We will <a href=\"https:\/\/www.benedictsol.com\/blogs\/gsp-215-week-4-homework-optimizing-program-performance\/\" class=\"read-more\">Read More &#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-217651","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/comments?post=217651"}],"version-history":[{"count":0,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/posts\/217651\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/media?parent=217651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/categories?post=217651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benedictsol.com\/blogs\/wp-json\/wp\/v2\/tags?post=217651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}