Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.advocacy > #413087
| From | owl <owl@rooftop.invalid> |
|---|---|
| Newsgroups | comp.os.linux.advocacy |
| Subject | Re: Snit hitting the glue bag early today |
| Date | 2017-05-05 06:18 +0000 |
| Organization | O.W.L. |
| Message-ID | <acv993.by93ap@rooftop.invalid> (permalink) |
| References | (9 earlier) <oefa57$1lg$2@dont-email.me> <z80b3.y88abhy@rooftop.invalid> <oegd8c$27u$3@dont-email.me> <zcv903ahbue.3u8@rooftop.invalid> <oegs1s$b3k$3@dont-email.me> |
DFS <nospam@dfs.com> wrote:
> On 5/4/2017 10:56 PM, owl wrote:
>> DFS <nospam@dfs.com> wrote:
>>> On 5/4/2017 3:49 PM, owl wrote:
>>>> DFS <nospam@dfs.com> wrote:
>>>
>>>
>>>>> bash == severely pwned
>>>>> C == severely pwned
>>>>>
>>>>
>>>> In your dreams. I see you got the python a bit faster, but C still
>>>> delivers an epic smackdown.
>>>
>>>> Python 0.010s
>>>> C 0.001s
>>>
>>>
>>>
>>> 14 lines of readable and maintainable python and about 30 minutes dev time
>>>
>>> 164 lines of laborious, spaghetti-ish C and how long to write?
>
> How long?
>
>
>
>> No spaghetti in that code.
>
> I pasted it into Notepad++ and it asked "You want-a Prego or you want-a
> Classico?" :)
>
>
> If you're not too busy, let's try a contest: shortest C to execute the
> features of my python program.
>
> inputs, options, processes and outputs are the same.
>
>
>
>
>>> I like C, but it's just not entertaining or productive for me at this
>>> time. And forget about using C to write db systems and reports, etc.
>>>
>>
>> Why? Talking to postgresql in C is straightforward.
>
>
> You've done a fair amount?
Hardly any.
> Is it too much work to show me:
>
> * connection
> * create simple table (name, date) with PK of your choice
> * add 1000 rows (5 random names, random dates within a range of one
> month)
> * extract rows (group by query: name, date, count(date))
> * print summary to stdout
> * save summary to .csv file
>
> All that stuff is easy and quick in python.
>
Have you posted python code for this?
>
>
>>> C = severely severely pwned
>>
>> Nope.
>
> Oh but it is.
I guess these are the queries you want. I have to say, it's pretty
slow. Nearly 8.5 seconds for a measly 1000 inserts.
Code at the bottom. You said you wanted it short, so I left
out all error checks. (Wouldn't want to spaghettify it).
anon@lowtide:~/code/pg$ gcc -Wall -o blah blah.c -lpq
anon@lowtide:~/code/pg$ time ./blah
"2017-01-03","58"
"2017-01-20","51"
"2017-01-30","56"
"2017-01-06","57"
"2017-01-01","74"
"2017-01-14","62"
"2017-01-08","66"
"2017-01-25","61"
"2017-01-12","54"
"2017-01-17","63"
"2017-01-11","59"
"2017-01-24","58"
"2017-01-10","74"
"2017-01-31","73"
"2017-01-13","63"
"2017-01-26","66"
"2017-01-09","77"
"2017-01-07","56"
"2017-01-28","73"
"2017-01-15","64"
"2017-01-05","66"
"2017-01-16","65"
"2017-01-22","62"
"2017-01-23","76"
"2017-01-29","68"
"2017-01-27","69"
"2017-01-18","58"
"2017-01-21","73"
"2017-01-02","64"
"2017-01-19","76"
"2017-01-04","58"
"norton","436"
"trixie","376"
"alice","409"
"ralph","380"
"moe","399"
real 0m8.498s
user 0m0.020s
sys 0m0.044s
anon@lowtide:~/code/pg$
anon@lowtide:~/code/pg$ cat dates.csv
"2017-01-03","58"
"2017-01-20","51"
"2017-01-30","56"
"2017-01-06","57"
"2017-01-01","74"
"2017-01-14","62"
"2017-01-08","66"
"2017-01-25","61"
"2017-01-12","54"
"2017-01-17","63"
"2017-01-11","59"
"2017-01-24","58"
"2017-01-10","74"
"2017-01-31","73"
"2017-01-13","63"
"2017-01-26","66"
"2017-01-09","77"
"2017-01-07","56"
"2017-01-28","73"
"2017-01-15","64"
"2017-01-05","66"
"2017-01-16","65"
"2017-01-22","62"
"2017-01-23","76"
"2017-01-29","68"
"2017-01-27","69"
"2017-01-18","58"
"2017-01-21","73"
"2017-01-02","64"
"2017-01-19","76"
"2017-01-04","58"
anon@lowtide:~/code/pg$
anon@lowtide:~/code/pg$ cat names.csv
"norton","436"
"trixie","376"
"alice","409"
"ralph","380"
"moe","399"
anon@lowtide:~/code/pg$
-------------------- blah.c -------------------
#include <stdio.h>
#include <stdlib.h>
#include <postgresql/libpq-fe.h>
#include <string.h>
#include <time.h>
int main(int argc, char *argv[])
{
PGconn *conn;
PGresult *result;
char query[200]={0};
int i;
char *names[]={"ralph","alice","norton","trixie","moe"};
FILE *fp1;
FILE *fp2;
fp1=fopen("dates.csv","w+");
fp2=fopen("names.csv","w+");
srand(time(NULL));
conn=PQconnectdb("dbname=dummydb host=localhost");
sprintf(query,"create table dummy (id serial primary key,"
"name varchar(20), date date)");
result=PQexec(conn,query);
for(i=0;i<1000;i++)
{
sprintf(query,"insert into dummy(name,date) values('%s','2017-01-%d')",
names[rand()%5],
rand()%31 + 1);
result=PQexec(conn,query);
}
sprintf(query,"select date,count(name) from dummy group by date");
result=PQexec(conn,query);
for(i=0;i<PQntuples(result);i++)
{
fprintf(fp1,"\"%s\",",PQgetvalue(result,i,0));
fprintf(stdout,"\"%s\",",PQgetvalue(result,i,0));
fprintf(fp1,"\"%s\"\n",PQgetvalue(result,i,1));
fprintf(stdout,"\"%s\"\n",PQgetvalue(result,i,1));
}
sprintf(query,"select name,count(date) from dummy group by name");
result=PQexec(conn,query);
for(i=0;i<PQntuples(result);i++)
{
fprintf(fp2,"\"%s\",",PQgetvalue(result,i,0));
fprintf(stdout,"\"%s\",",PQgetvalue(result,i,0));
fprintf(fp2,"\"%s\"\n",PQgetvalue(result,i,1));
fprintf(stdout,"\"%s\"\n",PQgetvalue(result,i,1));
}
PQclear(result);
PQfinish(conn);
fclose(fp1);
fclose(fp2);
return 0;
}
-----------------------------------------------
Back to comp.os.linux.advocacy | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-02 22:12 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-03 09:22 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-03 14:07 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-04 09:29 -0400
Re: Snit hitting the glue bag early today Sandman <mr@sandman.net> - 2017-05-04 16:42 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-04 20:06 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-04 20:12 +0000
Re: Snit hitting the glue bag early today chrisv <chrisv@nospam.invalid> - 2017-05-05 06:52 -0500
Re: Snit hitting the glue bag early today Marek Novotny <marek.novotny@marspolar.com> - 2017-05-05 10:32 -0500
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 13:22 -0400
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 13:01 -0400
Re: Snit hitting the glue bag early today Steve Carroll <fretwizzer@gmail.com> - 2017-05-04 13:16 -0700
Re: Snit hitting the glue bag early today Sandman <mr@sandman.net> - 2017-05-04 21:36 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-06 09:44 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-04 19:49 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-04 19:28 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 02:56 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-04 23:40 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 06:18 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 06:34 +0000
Re: Snit hitting the glue bag early today Sandman <mr@sandman.net> - 2017-05-05 07:07 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 07:29 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 16:48 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 20:49 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 13:02 -0400
Re: Snit hitting the glue bag early today Sandman <mr@sandman.net> - 2017-05-05 19:12 +0000
Re: Snit hitting the glue bag early today Snit <usenet@gallopinginsanity.com> - 2017-05-05 13:45 -0700
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 17:09 -0400
Re: Snit hitting the glue bag early today Sandman <mr@sandman.net> - 2017-05-05 21:41 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 13:00 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 20:14 +0000
Re: Snit hitting the glue bag early today Snit <usenet@gallopinginsanity.com> - 2017-05-05 13:44 -0700
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 23:51 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-06 04:48 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-06 10:06 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-06 15:50 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-07 13:09 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-07 18:39 +0000
Re: Snit hitting the glue bag early today Chris Ahlstrom <OFeem1987@teleworm.us> - 2017-05-05 05:28 -0400
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 13:02 -0400
csiph-web