XSL prob.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dimitre Novatchev

    #16
    Re: The solution (Was: Re: XSL prob.)

    > The time for a single conversion using MSXML4 on my PC is 0.3
    milliseconds.

    Some more accurate timing:

    The time for 104 conversions is ~ 7.5 milliseconds.

    This makes 0.073 milliseconds for a single conversion or ~ 13700 conversions
    per second.


    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL


    Comment

    • Martin Boehm

      #17
      Re: The solution (Was: Re: XSL prob.)

      "Dimitre Novatchev" <dnovatchev@yah oo.com> wrote in message
      news:bla4pt$9om b2$1@ID-152440.news.uni-berlin.de
      [color=blue]
      > The time for 104 conversions is ~ 7.5 milliseconds.
      >
      > This makes 0.073 milliseconds for a single conversion or ~ 13700
      > conversions per second.[/color]

      Just estimated the PHP solution:
      (I hold the difference between the power of your CPU and that of mine
      for quite negligible, and the amount RAM does not matter here. I used a
      for loop containing a call to the PGP date() function.)

      My 1.8 GHz P4 with 512 MB of RAM (Win2k, too) did 1.000.000 conversions
      in a 10 reiterations average of 7.57 seconds, this breaks down to about
      132100 per second. For a single conversion that would be (quite exactly)
      7,56998 * 10^-6 seconds, or ~0.076 milliseconds.

      I am amazed. :-)

      surrendering,

      Martin

      P.S.: Would you mind do post or mail the code you used so I can make a
      direct comparison on that? Thanks!


      Comment

      • Marrow

        #18
        Re: XSL prob.

        Hi Kenneth,

        Using some functions from our datetime_lib.xs l (www.marrowsoft.com -
        libraries included in the trial installer) you could do...

        <?xml version="1.0"?>
        <xsl:styleshe et version="1.0"
        xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
        <xsl:template match="/">
        <xsl:variable name="unix_time stamp" select="8759965 80"/>
        <xsl:variable name="jd1970010 1" select="2440588 "/>
        <xsl:call-template name="float-to-date-time">
        <xsl:with-param name="value" select="$jd1970 0101 + ($unix_timestam p div
        (24 * 60 * 60))"/>
        </xsl:call-template>
        </xsl:template>

        <!--
        =============== =============== =============== =============== ==============
        Template: float-to-date-time
        Description: Convert a floating point value representing a date/time to
        a date/time string.
        Parameters:-
        <value> the value to be converted
        <round-seconds> if true then the seconds are not quoted on the output
        and, if the seconds are 59 then hour/minute is rounded
        (this is useful because some processors have limited
        floating point precision to cope with the seconds)
        =============== =============== =============== =============== ============== -
        ->
        <xsl:template name="float-to-date-time">
        <xsl:param name="value" select="number( 0)"/>
        <xsl:param name="round-seconds" select="false() "/>
        <xsl:variable name="date">
        <xsl:call-template name="julian-day-to-date">
        <xsl:with-param name="julian-day" select="floor($ value)"/>
        </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="t1" select="$value - floor($value)"/>
        <xsl:variable name="h" select="floor($ t1 div (1 div 24))"/>
        <xsl:variable name="t2" select="$t1 - ($h * (1 div 24))"/>
        <xsl:variable name="m" select="floor($ t2 div (1 div 1440))"/>
        <xsl:variable name="t3" select="$t2 - ($m * (1 div 1440))"/>
        <xsl:choose>
        <xsl:when test="$round-seconds">
        <xsl:variable name="s" select="$t3 div (1 div 86400)"/>
        <xsl:variable name="h2">
        <xsl:choose>
        <xsl:when test="($s &gt;= 59) and ($m = 59)"><xsl:valu e-of select="$h +
        1"/></xsl:when>
        <xsl:otherwise> <xsl:value-of select="$h"/></xsl:otherwise>
        </xsl:choose>
        </xsl:variable>
        <xsl:variable name="m2">
        <xsl:choose>
        <xsl:when test="($s &gt;= 59) and ($m = 59)">0</xsl:when>
        <xsl:when test="($s &gt;= 59)"><xsl:valu e-of select="$m +
        1"/></xsl:when>
        <xsl:otherwise> <xsl:value-of select="$m"/></xsl:otherwise>
        </xsl:choose>
        </xsl:variable>
        <!-- pad final time result -->
        <xsl:variable name="hh" select="concat( substring('00', 1,2 -
        string-length(string($ h2))),string($h 2))"/>
        <xsl:variable name="mm" select="concat( substring('00', 1,2 -
        string-length(string($ m2))),string($m 2))"/>
        <!-- final output resultant -->
        <xsl:value-of select="concat( $date,'T',$hh,' :',$mm)"/>
        </xsl:when>
        <xsl:otherwis e>
        <xsl:variable name="s" select="floor($ t3 div (1 div 86400))"/>
        <!-- pad final time result -->
        <xsl:variable name="hh" select="concat( substring('00', 1,2 -
        string-length(string($ h))),string($h) )"/>
        <xsl:variable name="mm" select="concat( substring('00', 1,2 -
        string-length(string($ m))),string($m) )"/>
        <xsl:variable name="ss" select="concat( substring('00', 1,2 -
        string-length(string($ s))),string($s) )"/>
        <!-- final output resultant -->
        <xsl:value-of select="concat( $date,'T',$hh,' :',$mm,':',$ss) "/>
        </xsl:otherwise>
        </xsl:choose>
        </xsl:template>

        <!--
        =============== =============== =============== =============== ==============
        Template: julian-day-to-date
        Description: Convert a julian day to date
        Parameters:-
        <julian-day>
        =============== =============== =============== =============== ============== -
        ->
        <xsl:template name="julian-day-to-date">
        <xsl:param name="julian-day" select="number( 0)"/>
        <!-- pre-calcs -->
        <xsl:variable name="la" select="$julian-day + 68569"/>
        <xsl:variable name="n" select="floor(( 4 * $la) div 146097)"/>
        <xsl:variable name="lb" select="$la - floor((146097 * $n + 3) div 4)"/>
        <xsl:variable name="i" select="floor(( 4000 * ($lb + 1)) div 1461001)"/>
        <xsl:variable name="lc" select="$lb - floor((1461 * $i) div 4) + 31"/>
        <xsl:variable name="j" select="floor(( 80 * $lc) div 2447)"/>
        <xsl:variable name="day" select="$lc - floor((2447 * $j) div 80)"/>
        <xsl:variable name="ld" select="floor($ j div 11)"/>
        <xsl:variable name="month" select="$j + 2 - (12 * $ld)"/>
        <xsl:variable name="year" select="100 * ($n - 49) + $i + $ld"/>
        <!-- whole days -->
        <xsl:variable name="iday" select="floor($ day)"/>
        <!-- pad final result -->
        <xsl:variable name="sday" select="concat( substring('00', 1,2 -
        string-length(string($ iday))),string( $iday))"/>
        <xsl:variable name="smonth" select="concat( substring('00', 1,2 -
        string-length(string($ month))),string ($month))"/>
        <xsl:variable name="syear" select="concat( substring('00', 1,4 -
        string-length(string($ year))),string( $year))"/>
        <!-- final output -->
        <xsl:value-of select="concat( $syear,'-',$smonth,'-',$sday)"/>
        </xsl:template>

        </xsl:stylesheet>

        Cheers
        Marrow
        http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
        Jogue jogos online gratuitos diretamente no seu navegador, no celular, tablet ou computador em Jogos Rix. Não é necessário download nem cadastro.


        "Thomas" <ridder_dk@SLET _DETTEhotmail.c om> wrote in message
        news:7RRdb.1071 41$Kb2.3972494@ news010.worldon line.dk...[color=blue][color=green]
        > > And what's its meaning (e.g. number of seconds after some date)?[/color]
        >
        > Source: http://www.mysql.com/doc/en/Date_and...functions.html
        >
        > It would be a lot easier if they pull the data out of the database as a
        > readable date instead of unix timestamp, but they don't. :(
        >
        > Regards,
        >
        > Kenneth
        >
        >[/color]


        Comment

        • Bob Foster

          #19
          Re: The solution (Was: Re: XSL prob.)

          "Martin Boehm" <ng.tomalak@arc or.de> wrote in message
          news:3f78a61c$0 $23104$9b4e6d93 @newsread2.arco r-online.net...[color=blue]
          > "Dimitre Novatchev" <dnovatchev@yah oo.com> wrote in message
          > news:bla4pt$9om b2$1@ID-152440.news.uni-berlin.de
          >[color=green]
          > > The time for 104 conversions is ~ 7.5 milliseconds.
          > >
          > > This makes 0.073 milliseconds for a single conversion or ~ 13700
          > > conversions per second.[/color]
          >
          > Just estimated the PHP solution:
          > (I hold the difference between the power of your CPU and that of mine
          > for quite negligible, and the amount RAM does not matter here. I used a
          > for loop containing a call to the PGP date() function.)
          >
          > My 1.8 GHz P4 with 512 MB of RAM (Win2k, too) did 1.000.000 conversions
          > in a 10 reiterations average of 7.57 seconds, this breaks down to about
          > 132100 per second. For a single conversion that would be (quite exactly)
          > 7,56998 * 10^-6 seconds, or ~0.076 milliseconds.
          >
          > I am amazed. :-)[/color]

          I am, too. You did 1 million in 7.6 seconds and Dimitre did 104 thousand in
          7.5 seconds, yet his is slightly faster per conversion! That is truly
          amazing. But I believe 7.6 * 10^-6 seconds is 7.6 microseconds, which is
          0.0076 milliseconds.

          Bob Foster
          [color=blue]
          > surrendering,
          >
          > Martin
          >
          > P.S.: Would you mind do post or mail the code you used so I can make a
          > direct comparison on that? Thanks!
          >
          >[/color]


          Comment

          • Dimitre Novatchev

            #20
            Re: The solution (Was: Re: XSL prob.)

            > Just estimated the PHP solution:[color=blue]
            > (I hold the difference between the power of your CPU and that of mine
            > for quite negligible, and the amount RAM does not matter here. I used a
            > for loop containing a call to the PGP date() function.)
            >
            > My 1.8 GHz P4 with 512 MB of RAM (Win2k, too) did 1.000.000 conversions
            > in a 10 reiterations average of 7.57 seconds, this breaks down to about
            > 132100 per second. For a single conversion that would be (quite exactly)
            > 7,56998 * 10^-6 seconds, or ~0.076 milliseconds.
            >
            > I am amazed. :-)
            >
            > surrendering,
            >
            > Martin
            >
            > P.S.: Would you mind do post or mail the code you used so I can make a
            > direct comparison on that? Thanks![/color]

            Here it is -- just check (as I did) that the value of count($vNodes) is 104:

            <xsl:styleshe et version="1.0"
            xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

            <xsl:import href="E:\Progra m
            Files\Marrowsof t\Xselerator25\ Samples\Librari es\datetime_lib .xsl"/>

            <xsl:output method="text"/>

            <xsl:variable name="vDaySecs" select="86400"/>

            <xsl:template match="/">
            <xsl:variable name="vNodes"
            select="documen t('')//node() | document('')//@* |
            document('')//namespace::*"/>

            <xsl:variable name="vResult">
            <xsl:for-each select="$vNodes ">
            <xsl:call-template name="unix-timestamp-to-datetime">
            <xsl:with-param name="pTimeStam p" select="8759965 80"/>
            </xsl:call-template>
            </xsl:for-each>
            </xsl:variable>
            <!-- <xsl:value-of select="count($ vNodes)"/>-->
            </xsl:template>

            <xsl:template name="unix-timestamp-to-datetime">
            <xsl:param name="pTimeStam p" select="0"/>

            <xsl:variable name="vBase">
            <xsl:call-template name="date-to-julian-day">
            <xsl:with-param name="date" select="'1970-01-01'"/>
            </xsl:call-template>
            </xsl:variable>

            <xsl:call-template name="float-to-date-time">
            <xsl:with-param name="value" select="$vBase + $pTimeStamp div
            $vDaySecs"/>
            </xsl:call-template>
            </xsl:template>

            </xsl:stylesheet>


            P.S.
            1. This solution can be optimized still more by having a constant for vBase
            (2440588) and not calculating it every time. Then the result for 92
            conversions is 3.776 milliseconds, which makes:

            0.041 milliseconds for one conversion


            24390 conversions per second.


            2. This is not the first example of an efficient XSLT application. See my
            article in xml.com "EXSLT for MSXML" at the end of which there is a
            comparison table showing the timings of XSLT processors that implement the
            Sets module of EXSLT.

            The EXSLT implementation for MSXML4 was faster than 5 of them -- JD (Java),
            4XSLT (Python), .Net xsltTransform (C#), xsltProc (C) and Xalan J 2.4.1
            (Java).

            For those, who don't know -- the (Sets module of) EXSLT support for MSXML4
            is implemented in XSLT.

            So, in this case the XSLT implementation outperforms implementations written
            in such languages as C, C#, Java and Python.


            =====
            Cheers,

            Dimitre Novatchev.
            http://fxsl.sourceforge.net/ -- the home of FXSL


            Comment

            • Dimitre Novatchev

              #21
              Re: The solution (Was: Re: XSL prob.)

              > > I am amazed. :-)[color=blue]
              >
              > I am, too. You did 1 million in 7.6 seconds and Dimitre did 104 thousand[/color]
              in[color=blue]
              > 7.5 seconds, yet his is slightly faster per conversion! That is truly
              > amazing. But I believe 7.6 * 10^-6 seconds is 7.6 microseconds, which is
              > 0.0076 milliseconds.
              >
              > Bob Foster[/color]

              OK Guys,

              I was also amazed.

              Anyway, if something takes 0.073 milliseconds and is not the most frequently
              performed operation, shall we agree that this will not be a cause for a
              bottleneck in an application? Or even that an end user will not be able to
              perceive the difference between this operation and one that takes 7.6
              microseconds?

              This was just my point.


              =====
              Cheers,

              Dimitre Novatchev.
              http://fxsl.sourceforge.net/ -- the home of FXSL


              Comment

              • Martin Boehm

                #22
                Re: The solution (Was: Re: XSL prob.)

                "Bob Foster" <bobkfoster@com cast.net> wrote in message
                news:Yz8eb.6361 83$Ho3.130300@s ccrnsc03
                [color=blue]
                > You did 1 million in 7.6 seconds and Dimitre did 104
                > thousand in 7.5 seconds, yet his is slightly faster per conversion!
                > That is truly amazing.[/color]

                Owned.
                [color=blue]
                > But I believe 7.6 * 10^-6 seconds is 7.6 microseconds, which is
                > 0.0076 milliseconds.[/color]

                Oops, stupid of me. I am one order of magnitude less amazed. ;-)

                Martin


                Comment

                • Martin Boehm

                  #23
                  Re: The solution (Was: Re: XSL prob.)

                  "Dimitre Novatchev" <dnovatchev@yah oo.com> wrote in message
                  news:blb6ut$a3v ji$1@ID-152440.news.uni-berlin.de
                  [color=blue]
                  > I was also amazed.
                  >
                  > Anyway, if something takes 0.073 milliseconds and is not the most
                  > frequently performed operation, shall we agree that this will not be
                  > a cause for a bottleneck in an application?[/color]

                  As this evolved to be an academic kind of discussion - no. ;-)
                  But in terms of portability, homogeneity of implemetation and common
                  sense - yes.
                  [color=blue]
                  > Or even that an end user will not be able to perceive the difference
                  > between this operation and one that takes 7.6 microseconds?[/color]

                  Agreed.

                  Martin


                  Comment

                  • Bob Foster

                    #24
                    Re: The solution (Was: Re: XSL prob.)

                    "Martin Boehm" <ng.tomalak@arc or.de> wrote in message
                    news:3f793ec0$0 $23082$9b4e6d93 @newsread2.arco r-online.net...[color=blue]
                    > Oops, stupid of me. I am one order of magnitude less amazed. ;-)[/color]

                    Easy mistake to make. So your original point was that you thought PHP would
                    be faster and it was 10 times faster. Point made.

                    Dimitre responds that if not done very often the difference between 73
                    microseconds and 7.6 microseconds is insignificant. Point made.

                    It's good to see some actual numbers in performance discussions! Hats off to
                    both of you.

                    Bob Foster


                    Comment

                    • Dimitre Novatchev

                      #25
                      Re: The solution (Was: Re: XSL prob.)


                      "Bob Foster" <bobkfoster@com cast.net> wrote in message
                      news:fjKeb.6515 68$Ho3.135258@s ccrnsc03...[color=blue]
                      > "Martin Boehm" <ng.tomalak@arc or.de> wrote in message
                      > news:3f793ec0$0 $23082$9b4e6d93 @newsread2.arco r-online.net...[color=green]
                      > > Oops, stupid of me. I am one order of magnitude less amazed. ;-)[/color]
                      >
                      > Easy mistake to make. So your original point was that you thought PHP[/color]
                      would[color=blue]
                      > be faster and it was 10 times faster. Point made.[/color]

                      Actually with the optimization I reported -- pre-calculating 1970-01-01 as a
                      Julian day number, the XSLT solution becomes twice faster.

                      Therefore the PHP to XSLT performance ratio in this case is 4-5 times
                      faster.


                      =====
                      Cheers,

                      Dimitre Novatchev.
                      http://fxsl.sourceforge.net/ -- the home of FXSL


                      Comment

                      • Martin Boehm

                        #26
                        Re: The solution (Was: Re: XSL prob.)

                        "Dimitre Novatchev" <dnovatchev@yah oo.com> wrote in message
                        news:blb5nk$9s3 ct$1@ID-152440.news.uni-berlin.de
                        [color=blue][color=green]
                        >> P.S.: Would you mind do post or mail the code you used so I can make
                        >> a direct comparison on that? Thanks![/color]
                        >
                        > Here it is -- just check (as I did) that the value of count($vNodes)
                        > is 104:
                        >
                        > [...code sample...][/color]

                        For the sake of completeness, I ran the code on my machine, too.

                        I wrapped the transformation into VB (transformNode method), as it is a
                        little easier to access the complete time date (e.g. with milliseconds)
                        from there. I called the Win32 API function GetSystemTime for that
                        purpose.
                        [color=blue]
                        > 1. This solution can be optimized still more by having a constant
                        > for vBase (2440588) and not calculating it every time.[/color]

                        Done.

                        My input XML had 10.000 <timestamp> elements, and the XSL loop took 407
                        ms.
                        That breaks down to 0.0407 milliseconds per conversion.
                        [color=blue]
                        > 0.041 milliseconds for one conversion[/color]

                        That is, 24570 converstions per second.
                        [color=blue]
                        > 24390 conversions per second.[/color]

                        So, the 100 MHz my machine is faster make for an actual performance
                        increase of merely 0.74 percent. Or zero, in case you rounded the single
                        conversion time.

                        q.e.d.

                        Martin


                        Comment

                        • Dimitre Novatchev

                          #27
                          Re: The solution (Was: Re: XSL prob.)

                          Thanks. This matches exactly my timings.

                          Should I say that I enjoyed this dialog :o)


                          =====
                          Cheers,

                          Dimitre Novatchev.
                          http://fxsl.sourceforge.net/ -- the home of FXSL

                          "Martin Boehm" <ng.tomalak@arc or.de> wrote in message
                          news:3f7bf91d$0 $6592$9b4e6d93@ newsread4.arcor-online.net...[color=blue]
                          > "Dimitre Novatchev" <dnovatchev@yah oo.com> wrote in message
                          > news:blb5nk$9s3 ct$1@ID-152440.news.uni-berlin.de
                          >[color=green][color=darkred]
                          > >> P.S.: Would you mind do post or mail the code you used so I can make
                          > >> a direct comparison on that? Thanks![/color]
                          > >
                          > > Here it is -- just check (as I did) that the value of count($vNodes)
                          > > is 104:
                          > >
                          > > [...code sample...][/color]
                          >
                          > For the sake of completeness, I ran the code on my machine, too.
                          >
                          > I wrapped the transformation into VB (transformNode method), as it is a
                          > little easier to access the complete time date (e.g. with milliseconds)
                          > from there. I called the Win32 API function GetSystemTime for that
                          > purpose.
                          >[color=green]
                          > > 1. This solution can be optimized still more by having a constant
                          > > for vBase (2440588) and not calculating it every time.[/color]
                          >
                          > Done.
                          >
                          > My input XML had 10.000 <timestamp> elements, and the XSL loop took 407
                          > ms.
                          > That breaks down to 0.0407 milliseconds per conversion.
                          >[color=green]
                          > > 0.041 milliseconds for one conversion[/color]
                          >
                          > That is, 24570 converstions per second.
                          >[color=green]
                          > > 24390 conversions per second.[/color]
                          >
                          > So, the 100 MHz my machine is faster make for an actual performance
                          > increase of merely 0.74 percent. Or zero, in case you rounded the single
                          > conversion time.
                          >
                          > q.e.d.
                          >
                          > Martin
                          >
                          >[/color]


                          Comment

                          • Martin Boehm

                            #28
                            Re: The solution (Was: Re: XSL prob.)

                            "Dimitre Novatchev" <dnovatchev@yah oo.com> wrote in message
                            news:blgvvr$bc6 ds$1@ID-152440.news.uni-berlin.de
                            [color=blue]
                            > Should I say that I enjoyed this dialog :o)[/color]

                            Me, too. And I learned a lot.

                            Thanks,

                            Martin


                            Comment

                            • Bob Foster

                              #29
                              Re: The solution (Was: Re: XSL prob.)

                              "Dimitre Novatchev" <dnovatchev@yah oo.com> wrote in message
                              news:blgcvi$b2f g0$1@ID-152440.news.uni-berlin.de...[color=blue]
                              > "Bob Foster" <bobkfoster@com cast.net> wrote in message
                              > news:fjKeb.6515 68$Ho3.135258@s ccrnsc03...[color=green]
                              > > "Martin Boehm" <ng.tomalak@arc or.de> wrote in message
                              > > news:3f793ec0$0 $23082$9b4e6d93 @newsread2.arco r-online.net...[color=darkred]
                              > > > Oops, stupid of me. I am one order of magnitude less amazed. ;-)[/color]
                              > >
                              > > Easy mistake to make. So your original point was that you thought PHP[/color]
                              > would[color=green]
                              > > be faster and it was 10 times faster. Point made.[/color]
                              >
                              > Actually with the optimization I reported -- pre-calculating 1970-01-01 as[/color]
                              a[color=blue]
                              > Julian day number, the XSLT solution becomes twice faster.
                              >
                              > Therefore the PHP to XSLT performance ratio in this case is 4-5 times
                              > faster.[/color]

                              My hat is always off to you. I'm continually amazed at what you can squeeze
                              out of XSLT.

                              Bob Foster


                              Comment

                              • Dimitre Novatchev

                                #30
                                Re: The solution (Was: Re: XSL prob.)

                                [color=blue]
                                > My hat is always off to you. I'm continually amazed at what you can[/color]
                                squeeze[color=blue]
                                > out of XSLT.
                                >
                                > Bob Foster[/color]

                                In this case our hats should be off to

                                Marrow,

                                who is the author of datetime_lib.xs l.


                                =====
                                Cheers,

                                Dimitre Novatchev.
                                http://fxsl.sourceforge.net/ -- the home of FXSL


                                Comment

                                Working...