Trying to understand why this code runs so much faster in js than it does in C and other languages Ask Programming |
- Trying to understand why this code runs so much faster in js than it does in C and other languages
- Is there actual situations where MySQL temporary tables are the most efficient and effective solution?
- Does a list of list of all Github buttons exist somewhere?
- if else statement help
- Java "cannot find symbol" help
- Banking/money management API?
- How can I copy the html code from a website and get it to work?
- Given a job interview, suspicious!
- Need python beginner help for while
- what can you tell about how someone made their webpage/site by visiting the site/viewing page source?
- Help with HTML Canvas resizing issue
- Unity 3d on Click color change
- Stuck on Question
- Just need a little help with my Java program
- How do I create a seamless multi-photo carousel?
- Throwing exceptions in a SOAP web service
- Can I be a systems programmer with a BSc CS degree?
- Programming for no server response
- HELP NEEDED C++
- How to make an external application run in a window and treat the window as a desktop?
- Mac programming workflow
- I want to access data on a secure server and manipulate it with my computer without downloading it. Will manipulation without downloading keep the data safe?
- Logic to check if random playing card matches players guess
- Server tool allowing me to easily switch PHP and MySql versions ?
- Algorithm: Adjacency matrix from triangulation
Trying to understand why this code runs so much faster in js than it does in C and other languages Posted: 26 Sep 2018 08:29 AM PDT A while back I've written a small piece of code that looks for amicable numbers (pairs of integers for which the sum of divisors of the first equals to the second, and vice-versa https://en.wikipedia.org/wiki/Amicable_numbers) Originally I've written this code in Java but it was so long ago and I didn't know about git back then, so that piece went lost, but I've written it later in several other languages, with the same base algorithm: C, javascript, python, go and rust. Well, here's when things became a bit odd in my opinion... I expected the fastest run time to come from C, as it has been around the longest, and I expected javascript to be behind but not too much thanks to the V8 engine compile at run strategy... Not the case at all! when running them from 0 to a million, node ran the js code twice as fast as the compiled C code! (C finished in about 6 seconds, js in about 3) I recently discussed this with friends and they were as surprised as me. So I guess it's time to ask the internet. Here is the git repo with all the code: https://github.com/tomklino/friendly and here is the output when running and timing all of them on my laptop: https://pastebin.com/gv5kRg5z So if you have any insights as to why js is faster here (maybe implementation/optimization?), please share! [link] [comments] |
Posted: 26 Sep 2018 06:03 PM PDT My coworker brought up a debate at work where we currently use MySQL temporary tables with the justification that MySQL doesn't use indices when joining multiple tables. Supposedly, since we have pretty big data sets, with just using joins without the temporary tables the queries take literally minutes. I was wondering if this is in fact true and if it is, is it the "best" solution? [link] [comments] |
Does a list of list of all Github buttons exist somewhere? Posted: 26 Sep 2018 11:26 AM PDT I am refering to these. I have no idea what is their official name, they seem pretty useful, also useful would be to have a list of them, maybe along with the description of their usage in project. Does something like this exist? [link] [comments] |
Posted: 26 Sep 2018 06:03 PM PDT So this is my Income Tax Calculator that I built for my class homework. It works, but I want to make it a little better. how it works right now is that it will print out each statement for each of the different categories that the income will be taxed. What I would like is it to skip it printing out each income if the income is > 250000, but I still want it to calculate each category it needs to pass through. any hints or tips would be appreciated. forgot to mention that it's C++ // tax calculator.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include "pch.h" #include <iostream> #include <iomanip> #include <cmath> using namespace std; //calculating each category of tax percents to income int main() { } [link] [comments] |
Java "cannot find symbol" help Posted: 26 Sep 2018 03:46 PM PDT import java.util.Scanner; public class Problem1 { public static void main (String args[]){ Scanner scan = new Scanner(System.in); int counter=0, word_count=0; String w = scan.nextLine(); char l = scan.nextChar(); } } this is my code. it is saying Error: Pre command failed: Problem1.java:7: error: cannot find symbol char l = scan.nextChar(); ^ symbol: method nextChar() location: variable scan of type Scanner Problem1.java:11: error: cannot find symbol while (counter what im not sure what is wrong any suggestions would be great [link] [comments] |
Posted: 26 Sep 2018 02:26 PM PDT I'm looking for some kind of API or similar that I can use to manage my finances programmatically. In particular, I'm looking to be able to move money between my own accounts within the same bank or credit union. Ideally, I'd like to be able to transfer money to an exchange that supports algorithmic trading as well, but for now I'd be satisfied with just being able to set up transfers from my checking to savings and vice-versa, so that I can put together some more advanced automated budgeting stuff. I'm not looking to turn this into a publicly available app or anything, this is just for personal use, so legal regulations shouldn't be an issue considering I wouldn't be handling anyone else's money. Anyone know of any banks or products that might support this? I've found plaid, but from what I can tell it's only capable of querying data, and not moving money between accounts. [link] [comments] |
How can I copy the html code from a website and get it to work? Posted: 26 Sep 2018 10:29 AM PDT I want to get the code of this website: http://techslides.com/demos/d3/us-zoom-county.html I was able to just copy and paste the whole code to a file on my computer, but even after running it from localhost:800 using the python3 -m http.server command in terminal, it still does not work, and I am not sure why. [link] [comments] |
Given a job interview, suspicious! Posted: 26 Sep 2018 09:59 AM PDT I've been offered an interview to be an apprentice software developer at a company, however, they said first of all, I will be doing IT work, and I will progress to software development. This is to make sure I've done the 'ground work' before moving on to software development. Does anyone know if this is a thing or they just wanting cheap labour, and they have no intentions of progressing? [link] [comments] |
Need python beginner help for while Posted: 26 Sep 2018 12:58 PM PDT So i have to program an approximation of an integral with the sum of n rectangles, my problem is that i want it to ask for an other number over and over again untill 0 is asked to end the program. This is why i added a while True: but my problem is that it works , it ask for an other number BUT it keeps adding the first area result to the new area approximation result NOTE : 1.25 is the analytical answer example : if i enter n = 100 for the first time illl get 1.2500044499999 which makes sens, BUT when my program ask me for an other number ( since its not terminated ) and if i enter 100 it will add 1.2500044499999 + ( my new value here its 100 1.2500044499999) = 2.5 which is not what i want since its supposed to give me 1.25 so i'm kinda lost how do i restart it to 0 when it ask for a new number... thanks !!! heres my code ( python btw( ------------------------------------------------------------------------- ar = 0 if n > 10000: if n == 0: [link] [comments] |
Posted: 26 Sep 2018 12:33 PM PDT |
Help with HTML Canvas resizing issue Posted: 26 Sep 2018 03:38 AM PDT I am using this Codepen for HTML Canvas Signature field. However, every time I resize the screen the drawing disappears. How to make the drawing persist? [link] [comments] |
Unity 3d on Click color change Posted: 26 Sep 2018 10:58 AM PDT I want to create a unit 3d program where there is a object and on click it will change color, the only tutorial i found about this was this https://www.youtube.com/watch?v=6zNHaLdVk80 but it's in such a low res i can't understand what i'm supposed to type in the script, there is a download link but it doesn't work. I would appreciate your help :) [link] [comments] |
Posted: 26 Sep 2018 02:41 PM PDT Hello everyone, I really need help with is question. Thanks! Consult the following code for questions #18 - #21 for (int i = 0; i < size; i++) { cout << "Enter data value" << endl; cin >> input; for (int j = 0; j < size; j++) { if (freq[j] == 0) { data[j] = input; freq[j]++; high = j; break; } else if (data[j] == input) { freq[j]++; break; } } }
[link] [comments] |
Just need a little help with my Java program Posted: 26 Sep 2018 08:03 AM PDT Hey folks, I sure hope this is the right subreddit for this (please let me know if it's not). I'm doing my programming homework, which is to solve the N-Queens problem using a stack. Here is a useful link for understanding the N-Queens problem if you're curious: https://www.cs.colorado.edu/~main/supplements/pdf/notes07.pdf , though you don't need to understand the problem for my question. My problem is when I try to run my program, I get a error called "java.lang.ArrayIndexOutOfBoundsException: 0" and I'm not sure how to rectify this. This error also brings up my source code and highlights a line. Here is my program below, and the line that gets highlighted is: [link] [comments] |
How do I create a seamless multi-photo carousel? Posted: 26 Sep 2018 08:00 AM PDT I'm looking to create a photo "carousel" like the one at the bottom of this (https://www.squarespace.com/about/team/) page under "OUR TEAM." A group of seamless moving photos. I can't seem to dissect the coding they used to figure it out (disclaimer: I am a novice). I am looking to add this into a Squarespace site. It would be ideal if the photos are easy to swap/add/remove, as it will be used for an employee page (similar to as it is used on the provided link). Thanks in advance for any help! [link] [comments] |
Throwing exceptions in a SOAP web service Posted: 26 Sep 2018 07:48 AM PDT I am developing a SOAP web service and am working on exception handling. The web service logs into a system and performs a series of queries. There are several errors that can occur during connection/login and then there are the errors that can occur when I am performing the queries. Should each of these errors throw a SoapException so that the client can trap it? Looking at this article on SO, it appears that would be the case. Also, my web service returns 12 pieces of data when successful. I assume it is up to the calling client to look for the exception and capture the error message string that I will return? And I will tell them to expect a SoapException with a message if an error occurs. Is that enough for them to go on? [link] [comments] |
Can I be a systems programmer with a BSc CS degree? Posted: 25 Sep 2018 09:56 PM PDT Basically, I don't want to be an applications programmer, and I'd very much rather script and use Unix/Linux terminals and learn about/build upon OSes, than build applications like calculators, tables, etc. Considering I also want to go into DevOps, I feel like a Electrical Engineering and Computer Science (EECS) degree is overkill, as engineers typically don't work with DevOps staff, right? [link] [comments] |
Programming for no server response Posted: 26 Sep 2018 12:07 AM PDT Hi Folk, I work with a small IT company that codes a business admin software in Clarion. Here is our challenge: One of our clients has a dodgy network and we keep freezing. It isn't a loop because there is no processing. So as far as we can tell it looks like we are requesting data from the server and not receiving a response; in the mean time our software is waiting for a response so it effectively freezes. Here is my question: what is the logic for recovering from this? There is no error to catch (try..catch) or anything; we are simply waiting for a response. Any help/ideas would be greatly appreciated! [link] [comments] |
Posted: 26 Sep 2018 05:41 AM PDT Hi, guys. I need to end up this program by fixing some bugs. Umm. So, there's Turing machine. It executes data taken from the files 1.txt, 2.txt, 3.txt and 4.txt. Firstly, machine stays in a loop too long while executing 1.txt. It gives right answer, but it prints it too many times. Secondly, someone told me that saving the tape in a loop is quite illogical, so it would be great to change it into array. And thirdly, just simplify whole code that it would be more understandable. Here's my code: #include <algorithm> #include <vector> #include <fstream> #include <iterator> using namespace std; struct instruction { string current_state; char current_char; char next_char; int move; string next_state; }; istream& operator>>(istream& is, instruction& i) { is >> i.current_state >> i.current_char >> i.next_char; char move_ch; is >> move_ch; if(move_ch == 'R') i.move = 1; else if(move_ch == 'L') i.move = -1; else i.move = 0; return is >> i.next_state; } struct machine { int position; string state; string tape; bool execute(const instruction &i); bool end_of_tape() const { return position < 0 || position > tape.size(); } }; bool machine::execute(const instruction &i) { if(i.current_state != state || tape[position] != i.current_char) return false; state = i.next_state; tape[position] = i.next_char; position += i.move; return true; } istream & operator>>(istream &is, machine &m) { m.state = "0"; is >> m.position; return is >> m.tape; } int main() { string filename; cout << "Enter filename: "; cin >> filename; ifstream ifs(filename, ifstream::in); machine m; ifs >> m; vector<instruction> program; copy(istream_iterator<instruction>(ifs), istream_iterator<instruction>(), back_inserter(program)); for(size_t i = 0; !m.end_of_tape() && i < program.size();) { if (m.execute(program[i])) i = 0; else i++; cout << m.tape << endl; } cout << "HALT!"; return 0; } This is file 1.txt: 00V0000000001111*A000000000001111*B000000000000000000000000ZR000000000H000000 //tape //instructions 0 0 0 R 0 0 1 1 R 0 0 V V R 0 0 * * L 1 1 0 * R 2 1 1 * R 3 1 V V R 20 1 V V R 20 2 * 0 R 4 3 * 1 R 5 4 A A R 4 4 0 0 R 4 4 1 1 R 4 5 A A R 5 5 0 0 R 5 5 1 1 R 5 4 * * L 6 5 * * L 7 6 0 * R 8 6 1 * R 9 7 0 * R 10 7 1 * R 11 6 A A R 20 7 A A R 20 8 * 0 R 12 9 * 1 R 13 10 * 0 R 14 11 * 1 R 15 12 B B R 12 12 0 0 R 12 12 1 1 R 12 13 B B R 13 13 0 0 R 13 13 1 1 R 13 14 B B R 14 14 0 0 R 14 14 1 1 R 14 15 B B R 15 15 0 0 R 15 15 1 1 R 15 12 Z 0 L 16 13 Z 1 L 16 14 Z 1 L 16 15 Z 0 L 17 12 C 1 L 16 13 C 0 L 17 14 C 0 L 17 15 C 1 L 17 16 0 Z L 18 17 0 C L 18 18 A A L 18 18 B B L 18 18 * * L 18 18 0 0 L 18 18 1 1 L 18 18 V V R 0 20 A A R 20 20 B B R 20 20 * * R 20 20 0 0 R 20 20 1 1 R 20 20 Z 0 R 21 20 C 1 R 21 21 0 0 R X 21 1 1 R X In the end it should give 3 or 4 rows of similar tape fragments: 2.txt 0000*0000 0 0 0 R 0 0 1 1 R 0 0 * * L 1 1 0 1 R 0 1 1 0 L 1 3.txt 00000000000000000000000*0000 0 0 0 R 0 0 1 1 R 0 0 2 2 R 0 0 3 3 R 0 0 4 4 R 0 0 5 5 R 0 0 6 6 R 0 0 7 7 R 0 0 8 8 R 0 0 9 9 R 0 0 * * L 1 1 0 1 R 0 1 1 2 R 0 1 2 3 R 0 1 3 4 R 0 1 4 5 R 0 1 5 6 R 0 1 6 7 R 0 1 7 8 R 0 1 8 9 R 0 1 9 0 L 1 4.txt 000100000000000000001111111000000000000000010000 0 0 0 R 0 0 1 0 R 11 11 1 1 R 11 11 0 1 R 2 2 0 0 L 3 2 1 1 L 4 3 1 1 L 3 3 0 0 R 0 4 1 0 L 5 4 0 0 L 4 5 1 1 L 5 5 0 1 L 12 12 0 0 R 6 12 1 1 R 0 6 1 1 R 6 6 0 0 L 4 [link] [comments] |
How to make an external application run in a window and treat the window as a desktop? Posted: 26 Sep 2018 01:50 AM PDT The external application may not know it is running in a window. It may treat the window as a desktop with dimensions of the window. What is the way to do this? [link] [comments] |
Posted: 26 Sep 2018 04:21 AM PDT Programmers of reddit I'm in need of your help. I've been a Linux user for the last four years (btw I use arch) using i3 with a personalized terminal (switching between urxvt and termite). For programming I switch between VSCode and vim and have become very effective with both tools. Recently I've gotten a job where I have to use a Mac and IntelliJ and just can't seem to get the same workflow that I had in Linux. The projects are more complex than I'm used to so I'm hesitant to program everything in vim, but IntelliJ is such a bulky tool with a lot of features to learn. I also can't get a good set of good DE navigation tools and am constantly looking up cheatsheets to see if there's something annoying I can accomplish with keyboard shortcuts. If anyone has tips on how to increase programming productivity on a Mac, or has any cool tools: help a guy out! [link] [comments] |
Posted: 26 Sep 2018 06:45 AM PDT *EDIT* thanks for the replies. I will be a good boy. Hi, This title is worse than my titles usually are... I know nothing about security. I am supposed to not download data from a server because personal computers aren't as safe. I can do work on a secure, work computer, but I'd prefer to be able to use my personal machine. If I run a script that accesses the server data but never "downloads" it (using normal windows functions), is the data being brought to an unsecure place? Is the data being converted into some binary format and then downloaded? I figure the latter is pretty safe and it can't be decoded by evil people who may access my personal machine? Thanks [link] [comments] |
Logic to check if random playing card matches players guess Posted: 26 Sep 2018 02:49 AM PDT I'm making a card game where you can guess what a random playing card chosen from a deck will be. You have four buttons where you can choose Hearts, Clubs, Spades, and Diamonds. Then another set of buttons will let you choose ace, 2, 3, 4 ... king etc. If you choose only hearts, any card with hearts will let you win. If you choose queen, any queen will win. If you choose hearts AND queen there is only one right card (which would be a higher score). You can guess on any combination, even multiple ones - kind of like roulette. Anways I got it all down, the game itself, calculating odds etc - but the player will win on any card with ace OR hearts when you choose ace of hearts as a combination, for example. How would you set this up? A short explanation or pseudo code would do fine. [link] [comments] |
Server tool allowing me to easily switch PHP and MySql versions ? Posted: 26 Sep 2018 02:38 AM PDT It might sound like a very stupid question but I'm looking for a Windows tool to help me manage Apache, PHP and MySql painlessly in a dev setup. I'm looking for something that would allow me to easily switch version of PHP and MySql servers. Ideally, the tool would also help me painlessly installing new versions when they are released. - Mamp doesn't let me switch MySql versions (and only 2 versions of PHP at a time) - Wampserver doesn't include MySql 7 (and 8) - Xampp simply doesn't offer multiple versions of PHP nor MySql Currently I have these 3 tools installed at the same time and switch when needed, but it's too much of a pain to use and maintain. I'm willing to buy a licence for something that would allow me to be more efficient (and again : less frustrated). Thanks ! [link] [comments] |
Algorithm: Adjacency matrix from triangulation Posted: 26 Sep 2018 02:31 AM PDT Hello everyone. I am working with ply files which give you vertices and faces. Faces are defined as a triplet of points, and are presumed to have edges between them if you think of the object as a wireframe. (This isn't that important just motivating my question.) Anyway does anyone know an algorithm which efficiently takes a triangulation and generates an adjacency matrix or an adjacency list (actually list probably better). Meaning for node i, I need to find all the nodes that have an edge to them from i. Thanks in advance because right now all the algorithms that I have thought of seem to be super inefficient (creating a set for each node, and iterating over the faces and adding 2 other nodes for each node in the triplet to its set). [link] [comments] |
You are subscribed to email updates from AskProgramming. To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google, 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States |
No comments:
Post a Comment