improve this?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting improve this?
# 8  
Old 08-03-2005
Hey vino, thanks!

Apparently it was the 'expr' command that was slowing things down. I changed to '#!/usr/bin/ksh' and got a major speed up!
Here are the new 'time' outputs:

# time ./tonfro.sh 100
2005-11-11

real 0m0.18s
user 0m0.08s
sys 0m0.10s

# time ./tonfro.sh 10000
2032-12-19

real 0m4.02s
user 0m1.19s
sys 0m2.60s

# time ./tonfro.sh 100000
2279-05-19

real 0m38.60s
user 0m12.39s
sys 0m24.11s
# 9  
Old 08-03-2005
Doesn't anyone read the faqs? Look up Yesterdays Date/Date Arithmetic which mentions my script called datecalc. Switch to that and see what timings you get.
# 10  
Old 08-03-2005
Perderabo,
I know that your script is blinding quick (literally.. over a 1000 times faster). But you seem to be using some arithmetic that fits for your date range. Can you explain what exactly you are using?
# 11  
Old 08-03-2005
I got that formula on the internet. Actually I got several that did the same thing, timed them, and picked the fastest. I don't know why it works. But I do that that it works. I used the forumula to compute the mjd of of the first date in my range. Then I incremented the the calendar date and recomputed the mjd and verified that it increased by one. So the forumla works over the entire range that I support. I needed a finite range to run that verification. Where the range came from: 1860 is the first year that Alaska used the Gregorian calendar. Prior to that, it followed Russia which was on the old Julian calendar. So in 1860, for the first time, no Julian calendar was in use anywhere in the USA. 3999 is the last year where there is unanimous agreement in the calculation of leap year. I didn't want to join the year 4000 fight.
# 12  
Old 08-04-2005
Another way to cumpute any date in the past or in the future from today :
Code:
#------------------------------------------------------------------------
# Fonction .. : getDate [days [format]]
# Args ...... : $1 = days   : Offet from today [+|-]n  (def=0)
#               $2 = format : Format for the date display
# Example ... : o Yesterday => GetDate -1
#               o Tomorrow, yyyymmdd => GetDate +1 '+%Y%m%d'
#------------------------------------------------------------------------

function getDate { # GetDate days [format]

   l_days=0
   l_format=''

   if [ $# -ge 1 ]
   then
      l_days=$1
      shift
   fi

   l_format="$*"

   l_local_offset=$(echo $TZ | sed 's![^-0-9]*\([-0-9]*\).*!\1!')
   l_new_offset=`expr $l_local_offset - 24 \* $l_days`
   l_new_tz="`echo $TZ | sed 's!^\([^-0-9]*\)[-0-9]*\(.*\)$!\1'${l_new_offset}'\2!'`"

   TZ="$l_new_tz" date "$l_format"

   unset l_days l_format l_local_offset l_new_offset l_new_tz
}

#########  main script starts here
if [ $# -ne 1 ]
then
        echo "Usage: tonfro <delta>"
        exit 1
fi

getDate $1 '+%Y-%m-%d'


On my AIX box, the offset is limited in days to the range [-37854,+1855].
The original KSH GetDate function was written by PHV in the 'Unix Scripting FAQ' of www.tek-tips.com

time ./tonfro.sh 1
2005-08-05

réel 0m0,07s
util 0m0,01s
sys 0m0,03s

time ./tonfro.sh 10000
2032-12-20

réel 0m0,06s
util 0m0,01s
sys 0m0,03s
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Noob trying to improve

Hi everyone! This is my first post here, I hope that I will not already be violating any rule! I also would like to apologize in advance as my post will definitely be a noob post... please have patience and faith :rolleyes:! Now that I have set the ground rules :D:D, my objective is trying... (39 Replies)
Discussion started by: Ardzii
39 Replies

2. Shell Programming and Scripting

Improve script

Gents, Is there the possibility to improve this script to be able to have same output information. I did this script, but I believe there is a very short code to get same output here my script awk -F, '{if($10>0 && $10<=15) print $6}' tmp1 | sort -k1n | awk '{a++} END { for (n in a )... (23 Replies)
Discussion started by: jiam912
23 Replies

3. Programming

Improve the performance of my C++ code

Hello, Attached is my very simple C++ code to remove any substrings (DNA sequence) of each other, i.e. any redundant sequence is removed to get unique sequences. Similar to sort | uniq command except there is reverse-complementary for DNA sequence. The program runs well with small dataset, but... (11 Replies)
Discussion started by: yifangt
11 Replies

4. Shell Programming and Scripting

How to improve an script?

Gents. I have 2 different scripts for the same purpose: raw2csv_1 Script raw2csv_1 finish the process in less that 1 minute raw2csv_2 Script raw2csv_2 finish the process in more that 6 minutes. Can you please check if there is any option to improve the raw2csv_2. To finish the job... (4 Replies)
Discussion started by: jiam912
4 Replies

5. Shell Programming and Scripting

Improve sftp script

Dear all, I have written two scripts to transfer files to another server outside the company. One is a batch script , and the other script calls the batch script, send the files and archive the file sent. The problem is, that I want to get the list of files which have been uploaded the the... (10 Replies)
Discussion started by: arrals_vl
10 Replies

6. UNIX for Dummies Questions & Answers

How to improve the performance of this script?

Hi , i wrote a script to convert dates to the formate i want .it works fine but the conversion is tkaing lot of time . Can some one help me tweek this script #!/bin/bash file=$1 ofile=$2 cp $file $ofile mydates=$(grep -Po '+/+/+' $ofile) # gets 8/1/13 mydates=$(echo "$mydates" | sort |... (5 Replies)
Discussion started by: vikatakavi
5 Replies

7. AIX

improve sulog

I just wrote a very small script that improves readability on system sulog. The problem with all sulog is there is lack of clarity whether the info you are looking at is the most current. So if you just need a simple soution instead of going thru the trouble of writing a script that rotate logs and... (0 Replies)
Discussion started by: sparcguy
0 Replies

8. IP Networking

How to improve throughput?

I have a 10Gbps network link connecting two machines A and B. I want to transfer 20GB data from A to B using TCP. With default setting, I can use 50% bandwidth. How to improve the throughput? Is there any way to make throughput as close to 10Gbps as possible? thanks~ :) (3 Replies)
Discussion started by: andrewust
3 Replies

9. UNIX for Dummies Questions & Answers

Improve Performance

hi someone tell me which ways i can improve disk I/O and system process performance.kindly refer some commands so i can do it on my test machine.thanks, Mazhar (2 Replies)
Discussion started by: mazhar99
2 Replies

10. Shell Programming and Scripting

Can I improve this script ???

Hi all, Still a newbie and learning as I go ... as you do :) Have created this script to report on disc usage and I've just included the ChkSpace function this morning. It's the first time I've read a file (line-by-bloody-line) and would like to know if I can improve this script ? FYI - I... (11 Replies)
Discussion started by: Cameron
11 Replies
Login or Register to Ask a Question