Tag Info

49

Overall this is quite a nice module. Here are a few usability issues/nitpicks, though: When running the script, there is no easy way to stop it. CTRL+C does not work, I have to manually kill the process. This is probably because of how threading.Thread handles it, but I'm not sure. It would be nice if it was slightly easier to add a different handler than ...

41

Small issues before I get into the big one: Please make those setters private. The caller of this code has no business changing any of those values. Don't use ulong unless you are interoperating with unmanaged code. long has plenty of range. .NET uses signed quantities even for quantities that are logically always positive. It makes it easier to do things ...

38

The problem with an approach like that is that you you don't take into account that switching processors/cores is taking some time which will fake the results. This can be avoided by setting the ProcessorAffinity to use only a specific processor/core like so Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(2); // Use only the second core To ...

35

This is more of a design / algorithm / architecture review than of the code. There are some major issues the other answers didn't address. First of all, wasting network bandwidth running a speed-test on repeat seems like a bad idea. It will fill up your connection every hour (by default), so it hurts you personally if you happen to be doing something on ...

31

In the case of both if your while loops, you could easily make them for loops instead, which tends to be the best practice. int i = 1; while (i <= 100000) { // main while code i++ } Should be rewritten as: for (int i = 1; i <= 100000; i++) { // main while code } Likewise: i = 1; while (i <= 1000) {...

24

I'd like to say just one (yet IMO very important) thing: You're developing bad habits early! The point of classes is to eliminate (truly) global state and to manage it within classes and objects. You've really abused the use of global which is making your code harder to digest. There are cases where it's fine to use globals, where the generality of passing ...

22

I'd recommend the timeit module when measuring the execution time of functions. AFAIK, timeit disables the garbage collector for the duration of the test, which might give you better results overall. From here: timeit is more accurate, for three reasons: it repeats the tests many times to eliminate the influence of other tasks on your machine, ...

15

Concept Internet "speed" actually consists of multiple factors, including bandwidth, latency, and packet loss. What exactly are you trying to measure? If it's bandwidth (data transfer speed in bits per second), then you should also measure transfers of larger payloads, because the time to complete small transfers will tend to be dominated by latency ...

13

You've got some pretty poor variable names there. For example, what's m2 supposed to mean? I don't like the fact, that result generates itself. I would rather have two separate classes: one to run a benchmark and one to represent benchmark result. Also calling some Benchmark.Run method makes much more sense semantically than calling BenchmarkResult....

11

Why isn't using (SqlConnection con1 = new SqlConnection()) inside your while loop, right before using (SqlCommand cmd1 = new SqlCommand("dbo.GenerateNameAndSalary", con1))? Right now con1 is instantiated on line 14 and not disposed until line 82, yet it isn't used after line 39. You actually open con2 inside the con1 using block, as well as con3 which is ...

11

There are a number of things that you might employ to improve your program. Accuracy Is there any reason the strategy used and described below won't produce accurate results? Yes! There are many reasons, which are each enumerated separately in items below, followed by more general information about code style and structure. Understand System ...

10

I’m not familiar with the libraries that you’re using, but I can give some feedback on your general Python style: In Python, variable names are lowercase_with_underscores, not dromedaryCase. The exception is class names, which are PascalCase. There are very few comments or docstrings, which makes it hard to follow or debug your program. The convention is ...

10

I've never written code so I have no frame of reference. I wouldn't know by looking: This is very nicely done! Congrats! Good stuff: "use strict" Using an IIFE to contain everything Well-structured Copious comments Typically, beginners stop once something works - usually after changing stuff again and again until errors stop appearing - and neglect "...

10

Be more generic As I've suggested here, you should not force the use of an std::function. Instead, take any type of callable and either a fixed or an unlimited number of arguments, using std::invoke inside your implementation. More importantly, you really don't need multiple functions for a different number of arguments; use variadic templates, e.g. have a ...

9

While I would not say the code is awful, there are certainly a few areas that could stand to be cleaned up. I am not going to post modified code because I think there are areas where the "right thing to do" is going to depend on the intended use. First of all, your description implies that this will be used as a library class in your code. Library code ...

9

Important things: Have you read JMH Samples? Your benchmark does not have steady state. You can actually see that with diminishing performance iteration-to-iteration, and a large score error at the end. Measuring non-steady state benchmarks is a tricky business. Looping in benchmarks is generally discouraged, because loop unrolling optimizations, and ...

8

New solution At the beginning of your post, you mention having troubles with creating a timer and using the BIOS interrupts 86h and 15h: In a true real address mode environment it works correctly but I saw that an emulator like DOSBox messes up things. Tons of illegal reads and writes. I personally have never used these interrupts, nor have I ever ...

8

for loops Rather than using a while loop, and having an iterator variable i, You can use a for loop. A simple for loop is structured something like this: for(/* Declare i */; /* Check the value of i against a condition */; /* Change the value of i */) { ... } For example, this while loop, near the beginning of your code: int i = 1; while (i <...

8

You should move your connection string outside of the using statement using (SqlConnection con1 = new SqlConnection()) { Console.WriteLine(DateTime.UtcNow.ToString("hh:mm:ss.fffffff")); string name; string EmptyString = ""; string conString = ConfigurationManager.ConnectionStrings[args[0]].ToString(); int salary; int i = 1; ...

8

I think you need to think your use cases through a bit. What should this do during an outage? Do you want to enqueue a new tweet if a previous one hasn't been sent yet? Do you want to enqueue a special message for this, like "outage detected at hh:mm, resolved at hh:mm" (adjusted when sending after the outage)? Should it tweet at all? What exactly should ...

8

Your initial claim sounds about right to me, since for each iteration, checking at most cutoff elements for the insertion_point in the straight version (due to the restriction on the input) should become increasingly faster than checking logarithmic many in the binary version. Of course there is a lot more to consider like cache locality, but computational ...

8

Observations Very interesting question. The numbers I came up with when running the program are 10248 distinct values sorted Selection sort on 16384 items: 353 ms Insertion sort on 16384 items: 176 ms Which makes the insertion sort twice as fast as the selection sort. This is on Windows 10 using Visual Studio 2019 on a 4 year old Lenovo Thinkpad P50 with ...

8

Insertion sort allows a little known optimization. As coded, each iteration of an inner loop performs two comparisons: j > 0 and data[j - 1] > test_value. It is possible to get away with one: if (test_value < data[0]) { // No need to compare data anymore. Just shift. for (j = i; j > 0; j--) { data[j] = data[j - 1]; } } else { ...

7

Just a few little things: A public static getInstance() method is commonly used in the singleton pattern. However, you always create a new StopWatch. At least you should name it to createNewInstance(), if you want to keep the method at all. Many of your comments are unnecessary. For example the comment before isTimerRunning() doesn't help to understand the ...

7

Framework /* ********************************** * ADD YOUR PROBLEMS HERE! * ***********************************/ I'm sorry, did you just call this a framework? Never in my life have I seen a framework where I had to edit the sourcecode to make it usable. Let users of the framework pass the List<Problem<?>> problems to the ...

7

I think your algorithmic part is exceedingly verbose. One of the nicenesses of Python is how it can lead to code that reads almost like English. And for this particular problem, even leaving performance considerations aside, I think iteration is clearer than recursion. So I would rewrite things as: def digits_of(number): """Yields the digits of an ...

7

Inlining First of all, your inline function calls the non-inline function, so if the compiler is really paying attention to the inline specification, it's only affecting a single "layer" of invocation. inline long fib(unsigned n) { if (n < 2) return n; return fibonacci(n - 1) + fibonacci(n - 2); } To stand a chance of getting some good out of ...

7

Ugly typedef I'm not a big fan of this: typedef std::future<int> FutureResultInt; It's not significantly shorter or easier to read, it doesn't isolate the user from an underlying type, and it only serves to slow down my reading every time I hit it. That's somewhat subjective, of course, but I don't believe it adds value. I'd be happier with it if ...

6

From a usability perspective, this is a bit weird... public static final Task<?> buildCheckedIntTask(final String name, final IntSupplier benchmark, final int expect) { return new Task<Boolean>(name) { There's not really any need for a Task<Boolean> here, it could just as well be Task<Integer>. Additionally, as you know what ...

Only top voted, non community-wiki answers of a minimum length are eligible