]>
Commit | Line | Data |
---|---|---|
e7d8c919 MG |
1 | package WWW::Passmark; |
2 | ||
3 | use 5.014000; | |
4 | use strict; | |
5 | use warnings; | |
6 | use parent qw/Exporter/; | |
7 | ||
8 | our $VERSION = '0.001'; | |
9 | our @EXPORT_OK = qw/get_cpu_list get_gpu_list/; | |
10 | our @EXPORT = @EXPORT_OK; | |
11 | ||
12 | use WWW::Passmark::CPU; | |
13 | use WWW::Passmark::GPU; | |
14 | ||
15 | use HTML::TreeBuilder; | |
16 | use LWP::UserAgent; # TreeBuilder->new_from_url uses this | |
17 | use List::MoreUtils qw/natatime/; | |
18 | ||
19 | use Data::Dumper qw/Dumper/; | |
20 | ||
21 | our $CPU_URL = 'https://www.cpubenchmark.net/CPU_mega_page.html'; | |
22 | our $GPU_URL = 'https://www.videocardbenchmark.net/GPU_mega_page.html'; | |
23 | ||
24 | sub get_main_table { | |
25 | my ($url) = @_; | |
26 | my $tree = HTML::TreeBuilder->new_from_url($url); | |
27 | my $table = $tree->look_down(class => 'tablesorter'); | |
28 | my $iter = natatime 2, $tree->find('tbody')->find('tr'); | |
29 | ||
30 | my @results; | |
31 | while (my @items = $iter->()) { | |
32 | my ($item, $desc) = @items; | |
33 | push @results, [ map { $_->as_text } $item->find('td'), $desc->find('td') ] | |
34 | } | |
35 | ||
36 | @results | |
37 | } | |
38 | ||
39 | sub get_cpu_list { | |
40 | my @results = map { bless $_, 'WWW::Passmark::CPU' } get_main_table $CPU_URL; | |
41 | #bless \@results, 'WWW::Passmark::CPUList' | |
42 | \@results | |
43 | } | |
44 | ||
45 | sub get_gpu_list { | |
46 | my @results = map { bless $_, 'WWW::Passmark::GPU' } get_main_table $GPU_URL; | |
47 | #bless \@results, 'WWW::Passmark::GPUList' | |
48 | \@results | |
49 | } | |
50 | ||
51 | 1; | |
52 | __END__ | |
53 | ||
54 | =encoding utf-8 | |
55 | ||
56 | =head1 NAME | |
57 | ||
58 | WWW::Passmark - look up CPU/GPU benchmark results | |
59 | ||
60 | =head1 SYNOPSIS | |
61 | ||
62 | use WWW::Passmark; | |
63 | my $cpu_list = get_cpu_list; | |
64 | my $some_cpu = $cpu_list->[232]; | |
65 | say $some_cpu->name; # AMD Ryzen 7 2700X | |
66 | say $some_cpu->socket; # AM4 | |
67 | say $some_cpu->cpumark; # 17016 | |
68 | say $some_cpu->test_date; # Apr 2018 | |
69 | ||
70 | my $gpu_list = get_gpu_list; | |
71 | my $some_gpu = $gpu_list->[5]; | |
72 | say $some_gpu->name; # Radeon R9 Fury | |
73 | say $some_gpu->g3dmark; # 9212 | |
74 | ||
75 | =head1 DESCRIPTION | |
76 | ||
77 | This module is a scraper for Passmark software result websites. This | |
78 | is the first version of the module, which only supports two of the | |
79 | websites (cpubenchmark.net and videocardbenchmark.net) and offers few | |
80 | features. | |
81 | ||
82 | There are currently two functions, both exported by default. They are | |
83 | B<get_cpu_list> and B<get_gpu_list>, which download the list of all | |
84 | benchmark results for CPUs/GPUs and return an arrayref of objects of | |
85 | type L<WWW::Passmark::CPU> or L<WWW::Passmark::GPU>. Each such object | |
86 | represents one CPU/GPU, and contains its name and benchmark results. | |
87 | ||
88 | =head1 SEE ALSO | |
89 | ||
90 | L<https://www.cpubenchmark.net>, L<https://www.videocardbenchmark.net> | |
91 | ||
92 | =head1 AUTHOR | |
93 | ||
94 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> | |
95 | ||
96 | =head1 COPYRIGHT AND LICENSE | |
97 | ||
98 | Copyright (C) 2018 by Marius Gavrilescu | |
99 | ||
100 | This library is free software; you can redistribute it and/or modify | |
101 | it under the same terms as Perl itself, either Perl version 5.24.1 or, | |
102 | at your option, any later version of Perl 5 you may have available. | |
103 | ||
104 | ||
105 | =cut |