#StackBounty: #google-chrome #performance #https Slow HTTPS requests to all websites in Chrome

Bounty: 50

We have some wierd behavior on a lot of machines here. Computers are running Windows 10 x64 and Windows 8.1 x64 .. Using Internet Explorer we face no problems when visiting different websites, but Chrome is very very slow when trying to access HTTPS websites, and its ALL HTTPS websites, but only i Chrome. It is also on fresh chrome installs, even without any users logged into it or extensions installed.

The ONLY thing in Internet explorer which is slow? The download of Chrome. On one machine i even tried to download chrome through ninite, but that was also slow!

I have tried scanning the affected computers with Malware bytes and Windows Defender, but nothing shows up. In eitherway the computers work otherwise fine, so i dont expect there to be any vira or the like. I’ve tried changing DNS settings, reinstalling network drivers etc. but nothing helps.

Do you have any suggestions ?


Get this bounty!!!

#StackBounty: #performance #c #linked-list #console #windows Interactive console application to edit a sorted list

Bounty: 50

I am reading a book that has some difficult vocabulary and I, in order to understand the book thoroughly, decided to collect and lookup those words am not acquainted with, spend sometime learning them, and re-read the book.

I have created an interactive console application specifically for this purpose. The program’s main objectives are:

  • Open a file for reading and writing
  • Load data from file into linked list, if any, and sort them alphabetically.
  • Accept input from user, and search through the list for matches to display on screen.
  • If right key, is pressed, discard input. If Return key is pressed, save input to file, and if Escape key is pressed, cleanup and terminate program.

The key of interactivity is to show the user whether he added a word to the list or not, to avoid duplicates.

However, I have noticed that my implementation is hefty on the CPU, because when I run it, after short time, the fans become noisy, which make it hard for me to read and concentrate. Please advise on how can I optimize it and what improvements can be made.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <Windows.h>

struct G_list {
    char word[100];
    struct G_list *ptr;
};

typedef struct G_list G_list;

void add_and_sort(const char *str, G_list **head);
void free_list(G_list *head);

int cmp_at_begn(char *str, const char *substr);
void traverse_list(char *str, G_list *head);
void ClearScreen(void *hConsole);

int main(void)
{
    /* open file for reading and writing */
    const char filename[] = "Book.txt";
    FILE *fp = fopen(filename, "a+");
    if (!fp) {
        perror(filename);
        return 1;
    }

    /* ... */
    char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
    const size_t len = strlen(alphabet);

    /* allocate memory */
    G_list **wlist = (G_list **)malloc(sizeof(G_list *) * len);
    for (size_t i = 0; i < len; i++) {
        wlist[i] = (G_list *)malloc(sizeof(G_list));
        wlist[i]->ptr = NULL;
        wlist[i]->word[0] = 0;
    }

    /* load data from file */
    int c;
    char load[100];
    while (fgets(load, sizeof(load), fp)) {
        load[strcspn(load, "n")] = 0;
        c = *load - 'a';
        if (c < 0 || c >= len) {
            continue;
        }
        add_and_sort(load, wlist + c);
    }

    /* recieve input and display data */
    int index = 0;
    char buf[100] = { 0 };
    HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

    while (1) {
        // if backspace, delete character and traverse list
        if (GetAsyncKeyState(VK_BACK) == -32767) {
            if (index) {
                buf[--index] = '';
                ClearScreen(hStdout);
                printf("%sn............n", buf);
                if (index) {
                    traverse_list(buf, wlist[*buf - 'a']);
                }
            }
        }
        // if right-arrow key, discard input
        else if (GetAsyncKeyState(VK_RIGHT) == -32767) {
            index = 0;
            *buf = '';
            ClearScreen(hStdout);
            continue;
        }
        // if Enter, save to file
        else if (GetAsyncKeyState(VK_RETURN) == -32767) {
            if ((*buf - 'a') < 0 || (*buf - 'a') >= len) {
                continue;
            }
            add_and_sort(buf, &wlist[*buf - 'a']);
            fprintf(fp, "%sn", buf);
            index = 0;
            *buf = '';
            ClearScreen(hStdout);
            continue;
        }
        // if escape, terminate the program
        else if (GetAsyncKeyState(VK_ESCAPE) == -32767) {
            break;
        }
        // accept alphabet-input and display matches if any
        for (short i = 'A'; i <= 'Z'; i++) {
            if (GetAsyncKeyState(i) == -32767) {
                buf[index++] = (char)(i + 32);
                buf[index] = '';
                ClearScreen(hStdout);
                printf("%sn............n", buf);
                traverse_list(buf, wlist[*buf - 'a']);
            }
        }
    }

    /* release memory */
    fclose(fp);
    for (size_t i = 0; i < len; i++) {
        free_list(wlist[i]);
    }
    free(wlist);
}

void add_and_sort(const char *str, G_list **head)
{
    /* create node */
    G_list *node = (G_list *)malloc(sizeof(G_list));

    /* initialize node members */
    strcpy(node->word, str);
    node->ptr = NULL;

    /* ... */
    if ((*head)->word[0] == '') {
        *head = node;
        return;
    }
    else {
        while (1) {
            if (strcmp(str, (*head)->word) < 0) {
                G_list *tmp = *head;
                *head = node;
                node->ptr = tmp;
                break;
            }
            else {
                head = &((*head)->ptr);
                if (!*head) {
                    *head = node;
                    (*head)->ptr = NULL;
                    break;
                }
            }
        }
    }
}

void free_list(G_list *head)
{
    G_list *tmp;
    while (head) {
        tmp = head;
        head = head->ptr;
        free(tmp);
    }
}

// compare at beginning of line
int cmp_at_begn(char *str,
    const char *substr)
{
    if (!*str || !*substr) {
        return (*str == *substr);
    }
    else {
        while (*str && *substr) {
            if (*str++ != *substr++) {
                return 0;
            }
        }
    }
    return !(*substr);
}

void ClearScreen(void *hConsole)
{
    COORD coordScreen = { 0, 0 };    // home for the cursor 
    DWORD cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD dwConSize;
    // Get the number of character cells in the current buffer. 
    if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
    {
        return;
    }
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    // Fill the entire screen with blanks.
    if (!FillConsoleOutputCharacter(hConsole,        // Handle to console screen buffer 
        (TCHAR) ' ',     // Character to write to the buffer
        dwConSize,       // Number of cells to write 
        coordScreen,     // Coordinates of first cell 
        &cCharsWritten))// Receive number of characters written
    {
        return;
    }
    // Get the current text attribute.
    if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
    {
        return;
    }
    // Set the buffer's attributes accordingly.
    if (!FillConsoleOutputAttribute(hConsole,         // Handle to console screen buffer 
        csbi.wAttributes, // Character attributes to use
        dwConSize,        // Number of cells to set attribute 
        coordScreen,      // Coordinates of first cell 
        &cCharsWritten)) // Receive number of characters written
    {
        return;
    }
    // Put the cursor at its home coordinates.
    SetConsoleCursorPosition(hConsole, coordScreen);
}

void traverse_list(char *str, G_list *head)
{
    int v = 0;
    while (head) {
        if (cmp_at_begn(head->word, str)) {
            puts(head->word);
            v = 1;
        }
        else {
            if (v) break;
        }
        head = head->ptr;
    }
}


Get this bounty!!!

#StackBounty: #performance #c #linked-list #windows Interactive console application

Bounty: 50

I am reading a book that has some difficult vocabulary and I, in order to understand the book thoroughly, decided to collect and lookup those words am not acquainted with, spend sometime learning them, and re-read the book.

I have created an interactive console application specifically for this purpose. The program’s main objectives are:

  • Open a file for reading and writing
  • Load data from file into linked list, if any, and sort them alphabetically.
  • Accept input from user, and search through the list for matches to display on screen.
  • If right key, is pressed, discard input. If Return key is pressed, save input to file, and if Escape key is pressed, cleanup and terminate program.

The key of interactivity is to show the user whether he added a word to the list or not, to avoid duplicates.

However, I have noticed that my implementation is hefty on the CPU, because when I run it, after short time, the fans become noisy, which make it hard for me to read and concentrate. Please advise on how can I optimize it and what improvements can be made.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <Windows.h>

struct G_list {
    char word[100];
    struct G_list *ptr;
};

typedef struct G_list G_list;

void add_and_sort(const char *str, G_list **head);
void free_list(G_list *head);

int cmp_at_begn(char *str, const char *substr);
void traverse_list(char *str, G_list *head);
void ClearScreen(void *hConsole);

int main(void)
{
    /* open file for reading and writing */
    const char filename[] = "Book.txt";
    FILE *fp = fopen(filename, "a+");
    if (!fp) {
        perror(filename);
        return 1;
    }

    /* ... */
    char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
    const size_t len = strlen(alphabet);

    /* allocate memory */
    G_list **wlist = (G_list **)malloc(sizeof(G_list *) * len);
    for (size_t i = 0; i < len; i++) {
        wlist[i] = (G_list *)malloc(sizeof(G_list));
        wlist[i]->ptr = NULL;
        wlist[i]->word[0] = 0;
    }

    /* load data from file */
    int c;
    char load[100];
    while (fgets(load, sizeof(load), fp)) {
        load[strcspn(load, "n")] = 0;
        c = *load - 'a';
        if (c < 0 || c >= len) {
            continue;
        }
        add_and_sort(load, wlist + c);
    }

    /* recieve input and display data */
    int index = 0;
    char buf[100] = { 0 };
    HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

    while (1) {
        // if backspace, delete character and traverse list
        if (GetAsyncKeyState(VK_BACK) == -32767) {
            if (index) {
                buf[--index] = '';
                ClearScreen(hStdout);
                printf("%sn............n", buf);
                if (index) {
                    traverse_list(buf, wlist[*buf - 'a']);
                }
            }
        }
        // if right-arrow key, discard input
        else if (GetAsyncKeyState(VK_RIGHT) == -32767) {
            index = 0;
            *buf = '';
            ClearScreen(hStdout);
            continue;
        }
        // if Enter, save to file
        else if (GetAsyncKeyState(VK_RETURN) == -32767) {
            if ((*buf - 'a') < 0 || (*buf - 'a') >= len) {
                continue;
            }
            add_and_sort(buf, &wlist[*buf - 'a']);
            fprintf(fp, "%sn", buf);
            index = 0;
            *buf = '';
            ClearScreen(hStdout);
            continue;
        }
        // if escape, terminate the program
        else if (GetAsyncKeyState(VK_ESCAPE) == -32767) {
            break;
        }
        // accept alphabet-input and display matches if any
        for (short i = 'A'; i <= 'Z'; i++) {
            if (GetAsyncKeyState(i) == -32767) {
                buf[index++] = (char)(i + 32);
                buf[index] = '';
                ClearScreen(hStdout);
                printf("%sn............n", buf);
                traverse_list(buf, wlist[*buf - 'a']);
            }
        }
    }

    /* release memory */
    fclose(fp);
    for (size_t i = 0; i < len; i++) {
        free_list(wlist[i]);
    }
    free(wlist);
}

void add_and_sort(const char *str, G_list **head)
{
    /* create node */
    G_list *node = (G_list *)malloc(sizeof(G_list));

    /* initialize node members */
    strcpy(node->word, str);
    node->ptr = NULL;

    /* ... */
    if ((*head)->word[0] == '') {
        *head = node;
        return;
    }
    else {
        while (1) {
            if (strcmp(str, (*head)->word) < 0) {
                G_list *tmp = *head;
                *head = node;
                node->ptr = tmp;
                break;
            }
            else {
                head = &((*head)->ptr);
                if (!*head) {
                    *head = node;
                    (*head)->ptr = NULL;
                    break;
                }
            }
        }
    }
}

void free_list(G_list *head)
{
    G_list *tmp;
    while (head) {
        tmp = head;
        head = head->ptr;
        free(tmp);
    }
}

// compare at beginning of line
int cmp_at_begn(char *str,
    const char *substr)
{
    if (!*str || !*substr) {
        return (*str == *substr);
    }
    else {
        while (*str && *substr) {
            if (*str++ != *substr++) {
                return 0;
            }
        }
    }
    return !(*substr);
}

void ClearScreen(void *hConsole)
{
    COORD coordScreen = { 0, 0 };    // home for the cursor 
    DWORD cCharsWritten;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD dwConSize;
    // Get the number of character cells in the current buffer. 
    if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
    {
        return;
    }
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
    // Fill the entire screen with blanks.
    if (!FillConsoleOutputCharacter(hConsole,        // Handle to console screen buffer 
        (TCHAR) ' ',     // Character to write to the buffer
        dwConSize,       // Number of cells to write 
        coordScreen,     // Coordinates of first cell 
        &cCharsWritten))// Receive number of characters written
    {
        return;
    }
    // Get the current text attribute.
    if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
    {
        return;
    }
    // Set the buffer's attributes accordingly.
    if (!FillConsoleOutputAttribute(hConsole,         // Handle to console screen buffer 
        csbi.wAttributes, // Character attributes to use
        dwConSize,        // Number of cells to set attribute 
        coordScreen,      // Coordinates of first cell 
        &cCharsWritten)) // Receive number of characters written
    {
        return;
    }
    // Put the cursor at its home coordinates.
    SetConsoleCursorPosition(hConsole, coordScreen);
}

void traverse_list(char *str, G_list *head)
{
    int v = 0;
    while (head) {
        if (cmp_at_begn(head->word, str)) {
            puts(head->word);
            v = 1;
        }
        else {
            if (v) break;
        }
        head = head->ptr;
    }
}


Get this bounty!!!

#StackBounty: #android #performance #android-fragments #exception-handling How to override handleUncaughtException without changing its…

Bounty: 50

I asked this question some time back on Stackoverflow, the answer worked for me, It overrides thehandleUncaughtException, I save the exception and throws the default Unfortunately app has stopped working, but when i integrated this in my app, I am facing an issue.

This is the answer i got.

private Thread.UncaughtExceptionHandler defaultExceptionHandler;

    public void registerCrash(){
        defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();

        Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler(){
            @Override
            public void uncaughtException (Thread thread, Throwable e){
                handleUncaughtException (thread, e);
                if(defaultExceptionHandler != null){
                    defaultExceptionHandler.uncaughtException(thread, e);
                }
            }
        });
    } 

What it does, first it goes to handleUncaughtException (thread, e); i save the crash log in this method, then it reads this line

 if(defaultExceptionHandler != null){
    defaultExceptionHandler.uncaughtException(thread, e);
}

here we throw uncaught exception again, so it goes to the first line again, and again saves the exception, and this goes in loop, and application becomes not responding.

What i want is to save crash log, and then show the default Unfortunate message to user.

EDIT

On Application launch it reads this;

defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();

When application crashes, it reads these lines

Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler(){
    @Override
    public void uncaughtException (Thread thread, Throwable e){

        handleUncaughtException (thread, e); //Custom Method 

        if(defaultExceptionHandler != null){
            defaultExceptionHandler.uncaughtException(thread, e);
        }
    }

So it first goes to handleUncaughtException() there i have provided custom implementation, then it goes to this;

if(defaultExceptionHandler != null){
  defaultExceptionHandler.uncaughtException(thread, e);
}

The defaultExceptionHandler is never null; So it goes in a loop in case of multiple crashes.

I have tried adding count there, but it was 0 each time.


Get this bounty!!!

#StackBounty: #ubuntu #apache-2.4 #performance #logging #mod-wsgi Intermittent slow response & timeouts – Apache + mod_wsgi + Web2py

Bounty: 50

I’ve Ubuntu 14.04.5 LTS (i686) on a Digital Ocean droplet with 2×2.4GHzCPU & 4gb physical memory. I am running a web2py application on it with Apache and mod_wsgi. There are a few additional python modules installed on the box, like numpy and opencv2. The database is MySQL 5.5.

A WordPress website on another server calls this web2py application using php-curl. Usually the response time is 2-5 seconds. But occasionally it timeouts (response time goes to >1000 seconds). I’ve added logging points in the Web2py application and they tell that after reaching the application, everything completes in 2-3 seconds. But in Apache2 access log, response time logged as a number higher than 1000 seconds. In the access log, the request time is approximately the same when request is initiated from the WordPress website.

Can anyone point out how to find-out the reason of this intermittent slow response?

Thanks


Get this bounty!!!

#StackBounty: #performance #primes #pari-gp Prime number sieve using difference of two squares

Bounty: 50

Here is a working pari/gp implementation of prime number sieve. Is there something that I could change in code to achieve a better running time?

Sieve(g)=
{
A=vector(floor((g-1)/2));
for(n=1,floor((g-1)/2),
   A[n]=2*n+1);
for(x=3,floor(sqrt(g)),
   if(Mod(x,2)==1,i=0,i=1);
   forstep(y=i,x-3,[2],
      A[(x^2-y^2-1)/2]=0));
for(x=ceil(sqrt(g)),ceil((g+9)/6),
   i=ceil(sqrt(x^2-g));
   if(Mod(x+i,2)==0,i=i+1);
   forstep(y=i,x-3,[2],
      A[(x^2-y^2-1)/2]=0));
A=concat(2,A);
for(j=0,floor((g-1)/2),
   if(!(A[j+1]==0),print(A[j+1])))
}


Get this bounty!!!

#StackBounty: #performance #scheme #racket #benchmarking #chez-scheme (Chez) Scheme benchmarks?

Bounty: 50

Now that Chez Scheme is open-source, I wonder how it compares to Racket and other Schemes or languages in terms of performance, so that I could make informed choices about using them in my projects.

Unfortunately, I couldn’t find any relevant benchmarks.

I found the following:


https://ecraven.github.io/r7rs-benchmarks/benchmark.html

Problem: no Racket, or other languages


http://www.larcenists.org/benchmarksGenuineR6Linux.html

Problem: no Chez Scheme, or other languages


http://benchmarksgame.alioth.debian.org/

Problem: only Racket, questionable comparisions (For example, Python is not allowed to use Numpy where it would clearly help, while Racket is making FFI calls to GMP)


So, none of the benchmarks I found allow you to compare Racket to Chez, for example, or Chez to SBCL, or Java. Are there Chez benchmarks that give you a sense of how fast it is?

Chez Scheme is often said to be the fastest Scheme/Lisp around. We should know if it’s faster than, say, Java for your typical business logic application.


Get this bounty!!!

#StackBounty: #windows #performance #x86 Can I read the CPU performance counters from a user-mode program in Windows?

Bounty: 200

I would like to program and read the hardware performance counters offered on all recent x86 hardware.

On Linux there are the various perf_events systems to do this (and the perf utility to do it from outside an unmodified program).

Is there any such built-in facility in Windows?


Get this bounty!!!

#StackBounty: #performance #date #elasticsearch #filter Do additional date range filters increase the performance?

Bounty: 50

To an existing, large ElasticSearch 5 index, I want to add a date field, containing the date of the indexation of each document. Afterwards I want to query this index, to return all documents, created in the last minute.

In the ElasticSearch Ultimative Guide for version 1 it is mentioned, that adding additional filters for day, month and/or year can improve the performance drastically. Newer versions of the guide do not say so anymore.

Can I gain performance in ElasticSearch 5 with adding additional date filters?


Get this bounty!!!

#StackBounty: #performance #numerical-methods #symbolic-math #numerical-computing Symbolic vs Numeric Math – Performance

Bounty: 50

Do symbolic math calculations for solving nonlinear polynomial systems cause huge performance(calculation speed) disadvantage compared to numeric calculations? Are there any benchmark/data about this?

Found a related question: https://scicomp.stackexchange.com/questions/21754/symbolic-computation-vs-numerical-computation


Get this bounty!!!