Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.advocacy > #413331

Re: Snit hitting the glue bag early today

From owl <owl@rooftop.invalid>
Newsgroups comp.os.linux.advocacy
Subject Re: Snit hitting the glue bag early today
Date 2017-05-06 15:50 +0000
Organization O.W.L.
Message-ID <acv893qf.jig@rooftop.invalid> (permalink)
References (11 earlier) <oeias1$v75$2@dont-email.me> <zvz8v03.bu8ie@rooftop.invalid> <oejgv5$btg$2@dont-email.me> <pa80b.3yvevv45gv7j@rooftop.invalid> <oekkrm$eco$2@dont-email.me>

Show all headers | View raw


DFS <nospam@dfs.com> wrote:
> On 5/6/2017 12:48 AM, owl wrote:
> 
>> When I run it, it doesn't write to the db and there is no
>> record of the csv file that contained the 1000 records,
>> which appears to be the same file you write your summary
>> to, so...
>> 
>> The first code you had worked for writing to the db.
>> Also, the timer function you are using shows about 1/10
>> the usage that "time" reports as "real".
> 
>> 
>> dummydb=# \dt
>> No relations found.
>> dummydb=#
>> 
>> The only changes I made were to dbname and the path for colatest.csv.
> 
> 
> Thanks for testing it.
> 
> Probably just need a conn.commit() statement at line 14, right after the 
> io.close() call.
> 
> Later today I'll fix and update it to run 2 summaries/2 csv for a better 
> comparison.
> 

1,000,000 records:
Python 21.402 sec 
C      14.495 sec 

anon@lowtide:~/code/pg$ time ./dfscopy 1000000
2017-05-11 32541
2017-05-03 32530
2017-05-09 32480
2017-05-23 32440
2017-05-14 32414
2017-05-13 32393
2017-05-06 32386
2017-05-25 32380
2017-05-26 32379
2017-05-17 32355
...
.csv file written

3.340s prog exec

real    0m21.402s
user    0m3.360s
sys     0m0.072s
anon@lowtide:~/code/pg$ time ./tlah 1000000
NOTICE:  relation "dummy" already exists, skipping
2017-01-04 32739
2017-01-25 32596
2017-01-24 32552
2017-01-06 32490
2017-01-15 32448
2017-01-13 32438
2017-01-29 32437
2017-01-05 32419
2017-01-02 32384
2017-01-07 32352

real    0m14.495s
user    0m0.324s
sys     0m0.028s
anon@lowtide:~/code/pg$ 


dummydb=# \dt
         List of relations
 Schema |   Name   | Type  | Owner 
--------+----------+-------+-------
 public | colatest | table | anon
 public | dummy    | table | anon
(2 rows)

dummydb=# select count(*) from colatest;
  count  
---------
 1000000
(1 row)

dummydb=# select count(*) from dummy;
  count  
---------
 1000000
(1 row)

dummydb=#

----------------------- tlah.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 *fp3;
  FILE *fp4;
  fp3=fopen("jah.csv","w+"); 
  fp4=fopen("report.csv","w+");
  if(argc!=2)
  {
    fprintf(stderr,"usage: %s <count>\n",argv[0]);
    exit(1);
  }
  srand(time(NULL));
  conn=PQconnectdb("dbname=dummydb host=localhost");
  sprintf(query,"create table if not exists dummy (id serial primary key,"
                "name varchar(20), date date)"); 
  result=PQexec(conn,query);
  PQexec(conn,"delete from dummy");
  for(i=0;i<atoi(argv[1]);i++)
  {
     fprintf(fp3,"%s, 2017-01-%02d\n",names[rand()%5],rand()%31+1);
  } 
  fclose(fp3);
  result=PQexec(conn,"copy dummy(name,date) from \
'/home/anon/code/pg/jah.csv' with csv");
  sprintf(query,"select date,count(date) as cnt from dummy \
group by date order by count(date) desc, date limit 10;");
  result=PQexec(conn,query);
  for(i=0;i<PQntuples(result);i++)
  {
    fprintf(fp4,"%s %s\n",PQgetvalue(result,i,0), PQgetvalue(result,i,0));
    fprintf(stdout,"%s %s\n",PQgetvalue(result,i,0), PQgetvalue(result,i,1));
  }
  PQclear(result);
  PQfinish(conn);
  fclose(fp4);
  return 0;
}

--------------------------------------------------------

Back to comp.os.linux.advocacy | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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