This file is indexed.

/usr/include/d2/4.6/std/perf.d is in libphobos2-4.6-dev 0.29.1-4.6.3-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
// Written in the D programming language

/* /////////////////////////////////////////////////////////////////////////////
 * File:        perf.d
 *
 * Created      19th March 2004
 * Updated:     18th July 2004
 *
 * www:         http://www.digitalmars.com/
 *
 * Copyright (C) 2004 by Digital Mars
 * All Rights Reserved
 * Written by Matthew Wilson
 * http://www.digitalmars.com
 * License for redistribution is by either the Artistic License in artistic.txt,
 * or the LGPL
 *
 * ////////////////////////////////////////////////////////////////////////// */


/**
 * Platform-independent performance measurement and timing classes.
 *
 * $(D_PARAM PerformanceCounter) is the main platform-independent timer class provided,
 * covering the most typical use case, measuring elapsed wall-clock time.
 *
 * The module also provides several Windows-specific timers that can
 * be useful in specialized situations.
 *
 * Synopsis:
 ----
alias PerformanceCounter.interval_t interval_t;
auto timer = new PerformanceCounter;
timer.start();
// do computation
timer.stop();
interval_t elapsedMsec = timer.milliseconds;
writefln("Time elapsed: %s msec", elapsedMsec);
----
 * In particular note that $(D_PARAM stop()) must be called
 * before querying the elapsed time.
 *
 * These classes were ported to D from the
 * $(LINK2 http://stlsoft.org/,STLSoft C++ libraries),
 * which were documented in the article
 * "$(LINK2 http://www.windevnet.com/documents/win0305a/,
 * Win32 Performance Measurement Options)",
 * May 2003 issue of Windows Develper Network.
 *
 * Author:
 * Matthew Wilson
 *
 * Source:    $(PHOBOSSRC std/_perf.d)
 *
 * Macros:
 *      WIKI=Phobos/StdPerf
 */

module std.perf;

pragma(msg, "std.perf has been scheduled for deprecation. "
            "Please use std.datetime instead.");

version(Windows)
{

    private import std.c.windows.windows;

    /* ////////////////////////////////////////////////////////////////////////// */

    // This library provides performance measurement facilities

    /* ////////////////////////////////////////////////////////////////////////// */

    /** A performance counter that uses the most accurate measurement APIs available on the host machine

        On Linux, the implementation uses $(D_PARAM gettimeofday()).
        For Windows, $(D_PARAM QueryPerformanceCounter()) is used if available,
        $(D_PARAM GetTickCount()) otherwise.
    */
    class PerformanceCounter
    {
    private:
        alias   long    epoch_type;
    public:
        /// The type of the interval measurement (generally a 64-bit signed integer)
        alias   long    interval_t;

        deprecated alias interval_t interval_type;

    private:
        /** Class constructor
        */
        shared static this()
        {
            // Detects availability of the high performance hardware counter, and if
            // not available adjusts

            interval_t freq;
            if (QueryPerformanceFrequency(&freq))
            {
                sm_freq =   freq;
                sm_fn    =   &_qpc;
            }
            else
            {
                sm_freq =   1000;
                sm_fn    =   &_qtc;
            }
        }

    public:
        /** Starts measurement

            Begins a measurement period
        */
        void start()
        {
            sm_fn(m_start);
        }

        /** Ends measurement

            Marks the end of a measurement period.
            This must be called before querying the elapsed time with
            $(D_PARAM period_count), $(D_PARAM seconds),
            $(D_PARAM milliseconds), or $(D_PARAM microseconds).

            The $(D_PARAM stop()) method may be called multiple times without an intervening $(D_PARAM start()).
            Elapsed time is always measured from most recent $(D_PARAM start()) to the most recent
            $(D_PARAM stop()).
        */
        void stop()
        {
            sm_fn(m_end);
        }

    public:
        /** The elapsed count in the measurement period

            This represents the extent, in machine-specific increments, of the measurement period
        */
        interval_t periodCount() const
        {
            return m_end - m_start;
        }

        /** The number of whole seconds in the measurement period

            This represents the extent, in whole seconds, of the measurement period
        */
        interval_t seconds() const
        {
            return periodCount() / sm_freq;
        }

        /** The number of whole milliseconds in the measurement period

            This represents the extent, in whole milliseconds, of the measurement period
        */
        interval_t milliseconds() const
        {
            interval_t   result;
            interval_t   count   =      periodCount();

            if(count < 0x20C49BA5E353F7L)
            {
                result = (count * 1000) / sm_freq;
            }
            else
            {
                result = (count / sm_freq) * 1000;
            }

            return result;
        }

        /** The number of whole microseconds in the measurement period

            This represents the extent, in whole microseconds, of the measurement period
        */
        interval_t microseconds() const
        {
            interval_t   result;
            interval_t   count   =      periodCount();

            if(count < 0x8637BD05AF6L)
            {
                result = (count * 1000000) / sm_freq;
            }
            else
            {
                result = (count / sm_freq) * 1000000;
            }

            return result;
        }

    private:
        alias void function(out epoch_type interval)    measure_func;

        static void _qpc(out epoch_type interval)
        {
            QueryPerformanceCounter(&interval);
        }

        static void _qtc(out epoch_type interval)
        {
            interval = GetTickCount();
        }

    private:
        epoch_type              m_start;    // start of measurement period
        epoch_type              m_end;      // End of measurement period
        __gshared const interval_t          sm_freq;    // Frequency
        __gshared const measure_func    sm_fn;      // Measurement function
    }

    unittest
    {
        alias PerformanceCounter    counter_type;

        counter_type    counter = new counter_type();

        counter.start();
        for(int i = 0; i < 10000000; ++i)
        {   }
        counter.stop();

        counter_type.interval_t  us1 =   counter.microseconds();
        counter_type.interval_t  ms1 =   counter.milliseconds();
        counter_type.interval_t  s1     =   counter.seconds();

        for(int i = 0; i < 10000000; ++i)
        {   }
        counter.stop();

        counter_type.interval_t  us2 =   counter.microseconds();
        counter_type.interval_t  ms2 =   counter.milliseconds();
        counter_type.interval_t  s2     =   counter.seconds();

        assert(us2 >= us1);
        assert(ms2 >= ms1);
        assert(s2 >= s1);
    }

    /* ////////////////////////////////////////////////////////////////////////// */

    /** A low-cost, low-resolution performance counter

        This class provides low-resolution, but low-latency, performance monitoring.

        This class is available only on Windows, but
        is guaranteed to be meaningful on all Windows operating systems.
    */
    class TickCounter
    {
    private:
        alias   long    epoch_type;
    public:
        /** The interval type

            The type of the interval measurement (generally a 64-bit signed integer)
        */
        alias   long    interval_t;

        deprecated alias interval_t interval_type;

    public:

    public:
        /** Starts measurement

            Begins a measurement period
        */
        void start()
        {
            m_start = GetTickCount();
        }

        /** Ends measurement

            Marks the end of a measurement period.
            This must be called before querying the elapsed time with
            $(D_PARAM period_count), $(D_PARAM seconds),
            $(D_PARAM milliseconds), or $(D_PARAM microseconds).

            The $(D_PARAM stop()) method may be called multiple times without an intervening $(D_PARAM start()).
            Elapsed time is always measured from most recent $(D_PARAM start()) to the most recent
            $(D_PARAM stop()).
        */
        void stop()
        {
            m_end = GetTickCount();
        }

    public:
        /**
           The elapsed count in the measurement period

           This represents the extent, in machine-specific increments, of the measurement period
        */
        interval_t periodCount() const
        {
            return m_end - m_start;
        }

        /** The number of whole seconds in the measurement period

            This represents the extent, in whole seconds, of the measurement period
        */
        interval_t seconds() const
        {
            return periodCount() / 1000;
        }

        /** The number of whole milliseconds in the measurement period

            This represents the extent, in whole milliseconds, of the measurement period
        */
        interval_t milliseconds() const
        {
            return periodCount();
        }

        /** The number of whole microseconds in the measurement period

            This represents the extent, in whole microseconds, of the measurement period
        */
        interval_t microseconds() const
        {
            return periodCount() * 1000;
        }

    private:
        uint    m_start;    // start of measurement period
        uint    m_end;      // End of measurement period
    }

    unittest
    {
        alias TickCounter   counter_type;

        counter_type    counter = new counter_type();

        counter.start();
        for(int i = 0; i < 10000000; ++i)
        {   }
        counter.stop();

        counter_type.interval_t  us1 =   counter.microseconds();
        counter_type.interval_t  ms1 =   counter.milliseconds();
        counter_type.interval_t  s1     =   counter.seconds();

        for(int i = 0; i < 10000000; ++i)
        {   }
        counter.stop();

        counter_type.interval_t  us2 =   counter.microseconds();
        counter_type.interval_t  ms2 =   counter.milliseconds();
        counter_type.interval_t  s2     =   counter.seconds();

        assert(us2 >= us1);
        assert(ms2 >= ms1);
        assert(s2 >= s1);
    }

    /* ////////////////////////////////////////////////////////////////////////// */

    /** A performance counter that provides thread-specific performance timings

        This class uses the operating system's performance monitoring facilities to provide timing
        information pertaining to the calling thread only, irrespective of the activities of other
        threads on the system. This class does not provide meaningful timing information on operating
        systems that do not provide thread-specific monitoring.

        This class is available only on Windows.
    */
    class ThreadTimesCounter
    {
    private:
        alias   long    epoch_type;
    public:
        /** The interval type

            The type of the interval measurement (generally a 64-bit signed integer)
        */
        alias   long    interval_t;

        deprecated alias interval_t interval_type;

    public:
        /** Constructor

            Creates an instance of the class, and caches the thread token so that measurements will
            be taken with respect to the thread in which the class was created.
        */
        this()
        {
            m_thread = GetCurrentThread();
        }

    public:
        /** Starts measurement

            Begins a measurement period
        */
        void start()
        {
            FILETIME    creationTime;
            FILETIME    exitTime;

            GetThreadTimes(m_thread, &creationTime, &exitTime, cast(FILETIME*)&m_kernelStart, cast(FILETIME*)&m_userStart);
        }

        /** Ends measurement

            Marks the end of a measurement period.
            This must be called before querying the elapsed time with
            $(D_PARAM period_count), $(D_PARAM seconds),
            $(D_PARAM milliseconds), or $(D_PARAM microseconds).

            The $(D_PARAM stop()) method may be called multiple times without an intervening $(D_PARAM start()).
            Elapsed time is always measured from most recent $(D_PARAM start()) to the most recent
            $(D_PARAM stop()).
        */
        void stop()
        {
            FILETIME    creationTime;
            FILETIME    exitTime;

            GetThreadTimes(m_thread, &creationTime, &exitTime, cast(FILETIME*)&m_kernelEnd, cast(FILETIME*)&m_userEnd);
        }


    public:

        /** The elapsed count in the measurement period for kernel mode activity

            This represents the extent, in machine-specific increments, of the measurement period for kernel mode activity
        */
        interval_t kernelPeriodCount() const
        {
            return m_kernelEnd - m_kernelStart;
        }
        /** The number of whole seconds in the measurement period for kernel mode activity

            This represents the extent, in whole seconds, of the measurement period for kernel mode activity
        */
        interval_t kernelSeconds() const
        {
            return kernelPeriodCount() / 10000000;
        }
        /** The number of whole milliseconds in the measurement period for kernel mode activity

            This represents the extent, in whole milliseconds, of the measurement period for kernel mode activity
        */
        interval_t kernelMilliseconds() const
        {
            return kernelPeriodCount() / 10000;
        }
        /** The number of whole microseconds in the measurement period for kernel mode activity

            This represents the extent, in whole microseconds, of the measurement period for kernel mode activity
        */
        interval_t kernelMicroseconds() const
        {
            return kernelPeriodCount() / 10;
        }


        /** The elapsed count in the measurement period for user mode activity

            This represents the extent, in machine-specific increments, of the measurement period for user mode activity
        */
        interval_t userPeriodCount() const
        {
            return m_userEnd - m_userStart;
        }
        /** The number of whole seconds in the measurement period for user mode activity

            This represents the extent, in whole seconds, of the measurement period for user mode activity
        */
        interval_t userSeconds() const
        {
            return userPeriodCount() / 10000000;
        }
        /** The number of whole milliseconds in the measurement period for user mode activity

            This represents the extent, in whole milliseconds, of the measurement period for user mode activity
        */
        interval_t userMilliseconds() const
        {
            return userPeriodCount() / 10000;
        }
        /** The number of whole microseconds in the measurement period for user mode activity

            This represents the extent, in whole microseconds, of the measurement period for user mode activity
        */
        interval_t userMicroseconds() const
        {
            return userPeriodCount() / 10;
        }


        /** The elapsed count in the measurement period

            This represents the extent, in machine-specific increments, of the measurement period
        */
        interval_t periodCount() const
        {
            return kernelPeriodCount() + userPeriodCount();
        }

        /** The number of whole seconds in the measurement period

            This represents the extent, in whole seconds, of the measurement period
        */
        interval_t seconds() const
        {
            return periodCount() / 10000000;
        }

        /** The number of whole milliseconds in the measurement period

            This represents the extent, in whole milliseconds, of the measurement period
        */
        interval_t milliseconds() const
        {
            return periodCount() / 10000;
        }

        /** The number of whole microseconds in the measurement period

            This represents the extent, in whole microseconds, of the measurement period
        */
        interval_t microseconds() const
        {
            return periodCount() / 10;
        }


    private:
        epoch_type  m_kernelStart;
        epoch_type  m_kernelEnd;
        epoch_type  m_userStart;
        epoch_type  m_userEnd;
        HANDLE      m_thread;
    }

    unittest
    {
        alias ThreadTimesCounter    counter_type;

        counter_type    counter = new counter_type();

        counter.start();
        for(int i = 0; i < 10000000; ++i)
        {   }
        counter.stop();

        counter_type.interval_t  us1 =   counter.microseconds();
        counter_type.interval_t  ms1 =   counter.milliseconds();
        counter_type.interval_t  s1     =   counter.seconds();

        for(int i = 0; i < 10000000; ++i)
        {   }
        counter.stop();

        counter_type.interval_t  us2 =   counter.microseconds();
        counter_type.interval_t  ms2 =   counter.milliseconds();
        counter_type.interval_t  s2     =   counter.seconds();

        assert(us2 >= us1);
        assert(ms2 >= ms1);
        assert(s2 >= s1);
    }

    /* ////////////////////////////////////////////////////////////////////////// */

    /** A performance counter that provides process-specific performance timings

        This class uses the operating system's performance monitoring facilities to provide timing
        information pertaining to the calling process only, irrespective of the activities of other
        processes on the system. This class does not provide meaningful timing information on operating
        systems that do not provide process-specific monitoring.

        This class is available only on Windows.
    */
    class ProcessTimesCounter
    {
    private:
        alias   long    epoch_type;
    public:
        /** The interval type

            The type of the interval measurement (generally a 64-bit signed integer)
        */
        alias   long    interval_t;

        deprecated alias interval_t interval_type;

    private:
        /** Class constructor

        */
        shared static this()
        {
            sm_process = GetCurrentProcess();
        }

    public:
        /** Starts measurement

            Begins a measurement period
        */
        void start()
        {
            FILETIME    creationTime;
            FILETIME    exitTime;

            GetProcessTimes(sm_process, &creationTime, &exitTime, cast(FILETIME*)&m_kernelStart, cast(FILETIME*)&m_userStart);
        }

        /** Ends measurement

            Marks the end of a measurement period.
            This must be called before querying the elapsed time with
            $(D_PARAM period_count), $(D_PARAM seconds),
            $(D_PARAM milliseconds), or $(D_PARAM microseconds).

            The $(D_PARAM stop()) method may be called multiple times without an intervening $(D_PARAM start()).
            Elapsed time is always measured from most recent $(D_PARAM start()) to the most recent
            $(D_PARAM stop()).
        */
        void stop()
        {
            FILETIME    creationTime;
            FILETIME    exitTime;

            GetProcessTimes(sm_process, &creationTime, &exitTime, cast(FILETIME*)&m_kernelEnd, cast(FILETIME*)&m_userEnd);
        }

    public:
        /** The elapsed count in the measurement period for kernel mode activity

            This represents the extent, in machine-specific increments, of the measurement period for kernel mode activity
        */
        interval_t kernelPeriodCount() const
        {
            return m_kernelEnd - m_kernelStart;
        }
        /** The number of whole seconds in the measurement period for kernel mode activity

            This represents the extent, in whole seconds, of the measurement period for kernel mode activity
        */
        interval_t kernelSeconds() const
        {
            return kernelPeriodCount() / 10000000;
        }
        /** The number of whole milliseconds in the measurement period for kernel mode activity

            This represents the extent, in whole milliseconds, of the measurement period for kernel mode activity
        */
        interval_t kernelMilliseconds() const
        {
            return kernelPeriodCount() / 10000;
        }
        /** The number of whole microseconds in the measurement period for kernel mode activity

            This represents the extent, in whole microseconds, of the measurement period for kernel mode activity
        */
        interval_t kernelMicroseconds() const
        {
            return kernelPeriodCount() / 10;
        }


        /** The elapsed count in the measurement period for user mode activity

            This represents the extent, in machine-specific increments, of the measurement period for user mode activity
        */
        interval_t userPeriodCount() const
        {
            return m_userEnd - m_userStart;
        }
        /** The number of whole seconds in the measurement period for user mode activity

            This represents the extent, in whole seconds, of the measurement period for user mode activity
        */
        interval_t userSeconds() const
        {
            return userPeriodCount() / 10000000;
        }
        /** The number of whole milliseconds in the measurement period for user mode activity

            This represents the extent, in whole milliseconds, of the measurement period for user mode activity
        */
        interval_t userMilliseconds() const
        {
            return userPeriodCount() / 10000;
        }
        /** The number of whole microseconds in the measurement period for user mode activity

            This represents the extent, in whole microseconds, of the measurement period for user mode activity
        */
        interval_t userMicroseconds() const
        {
            return userPeriodCount() / 10;
        }

        /** The elapsed count in the measurement period

            This represents the extent, in machine-specific increments, of the measurement period
        */
        interval_t periodCount() const
        {
            return kernelPeriodCount() + userPeriodCount();
        }

        /** The number of whole seconds in the measurement period

            This represents the extent, in whole seconds, of the measurement period
        */
        interval_t seconds() const
        {
            return periodCount() / 10000000;
        }

        /** The number of whole milliseconds in the measurement period

            This represents the extent, in whole milliseconds, of the measurement period
        */
        interval_t milliseconds() const
        {
            return periodCount() / 10000;
        }

        /** The number of whole microseconds in the measurement period

            This represents the extent, in whole microseconds, of the measurement period
        */
        interval_t microseconds() const
        {
            return periodCount() / 10;
        }

    private:
        epoch_type      m_kernelStart;
        epoch_type      m_kernelEnd;
        epoch_type      m_userStart;
        epoch_type      m_userEnd;
        __gshared HANDLE        sm_process;
    }

    unittest
    {
        alias ProcessTimesCounter   counter_type;

        counter_type    counter = new counter_type();

        counter.start();
        for(int i = 0; i < 10000000; ++i)
        {   }
        counter.stop();

        counter_type.interval_t  us1 =   counter.microseconds();
        counter_type.interval_t  ms1 =   counter.milliseconds();
        counter_type.interval_t  s1     =   counter.seconds();

        for(int i = 0; i < 10000000; ++i)
        {   }
        counter.stop();

        counter_type.interval_t  us2 =   counter.microseconds();
        counter_type.interval_t  ms2 =   counter.milliseconds();
        counter_type.interval_t  s2     =   counter.seconds();

        assert(us2 >= us1);
        assert(ms2 >= ms1);
        assert(s2 >= s1);
    }

    /* ////////////////////////////////////////////////////////////////////////// */
}
else version(Posix)
{
    extern (C)
    {
        private struct timeval
        {
            int tv_sec;    // The number of seconds, since Jan. 1, 1970, in the time value.
            int tv_usec;   // The number of microseconds in the time value.
        };
        private struct timezone
        {
            int tz_minuteswest; // minutes west of Greenwich.
            int tz_dsttime;     // type of dst corrections to apply.
        };
        private void gettimeofday(timeval *tv, timezone *tz);
    }

    /* ////////////////////////////////////////////////////////////////////////// */

    class PerformanceCounter
    {
        // documentation is in the Windows version of the class above


    private:
        alias   timeval epoch_type;
    public:
        alias   long    interval_t;

    public:
        void start()
        {
            timezone tz;

            gettimeofday(&m_start, &tz);
        }

        void stop()
        {
            timezone tz;

            gettimeofday(&m_end, &tz);
        }

    public:
        interval_t periodCount() const
        {
            return microseconds;
        }

        interval_t seconds() const
        {
            interval_t   start   =      cast(interval_t)m_start.tv_sec + cast(interval_t)m_start.tv_usec / (1000 * 1000);
            interval_t   end        =   cast(interval_t)m_end.tv_sec      + cast(interval_t)m_end.tv_usec   / (1000 * 1000);

            return end - start;
        }

        interval_t milliseconds() const
        {
            interval_t   start   =      cast(interval_t)m_start.tv_sec * 1000 + cast(interval_t)m_start.tv_usec / 1000;
            interval_t   end        =   cast(interval_t)m_end.tv_sec      * 1000 + cast(interval_t)m_end.tv_usec   / 1000;

            return end - start;
        }

        interval_t microseconds() const
        {
            interval_t   start   =      cast(interval_t)m_start.tv_sec * 1000 * 1000 + cast(interval_t)m_start.tv_usec;
            interval_t   end        =   cast(interval_t)m_end.tv_sec      * 1000 * 1000 + cast(interval_t)m_end.tv_usec;

            return end - start;
        }

    private:
        epoch_type  m_start;  // start of measurement period
        epoch_type  m_end;    // End of measurement period
    }

    unittest
    {
        alias PerformanceCounter    counter_type;

        counter_type    counter = new counter_type();

        counter.start();
        for(int i = 0; i < 10000000; ++i)
        {   }
        counter.stop();

        counter_type.interval_t  us1 =   counter.microseconds();
        counter_type.interval_t  ms1 =   counter.milliseconds();
        counter_type.interval_t  s1     =   counter.seconds();

        for(int i = 0; i < 10000000; ++i)
        {   }
        counter.stop();

        counter_type.interval_t  us2 =   counter.microseconds();
        counter_type.interval_t  ms2 =   counter.milliseconds();
        counter_type.interval_t  s2     =   counter.seconds();

        assert(us2 >= us1);
        assert(ms2 >= ms1);
        assert(s2 >= s1);
    }

    /* ////////////////////////////////////////////////////////////////////////// */
}
else
{
    const int platform_not_supported = 0;

    static assert(platform_not_supported);
}